struts2學習(7)struts2中的帶參數的結果集

 

struts2中的帶參數的結果集

struts2中如果是redirect跳轉,需要傳遞參數時:

1、 url中調用Action

http://localhost:8080/struts2_1800_ResultWithParams/user.action?type=1

 

2、 struts.xml配置文件:

<struts>

    <!-- Add packages here -->

    <constant name="struts.devMode" value="true" />

    <package name="resultType" namespace="/" extends="struts-default">

       <action name="user" class="net.dreamcreating.UserAction">

           <result type="redirect">/user_success.jsp?t=${type}</result>

       </action>

    </package>

</struts>

 

3、 在UserAction中包括屬性:type (程序如下所示)

package net.dreamcreating;

 

import com.opensymphony.xwork2.ActionSupport;

 

public class UserAction extends ActionSupport {

 

    private static final long serialVersionUID = 1L;

    private int type;

    public int getType() {

       return type;

    }

    public void setType(int type) {

       this.type = type;

    }

    @Override

    public String execute() throws Exception {

       return SUCCESS;

    }

}

 

4、 在user_success.jsp頁面中獲取t的值:

從值棧取值:<s:property value="t"/><br/>(獲取不到值)

actioncontext中取值:<s:property value="#parameters.t"/>(可以獲取到值)

發佈了132 篇原創文章 · 獲贊 18 · 訪問量 53萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章