struts2学习(7)struts2中的带参数的结果集

来源:互联网 发布:靠谱网络危机公关公司 编辑:程序博客网 时间:2024/05/22 12:30
 

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"/>(可以获取到值)

原创粉丝点击