struts2_10_带参数的结果集

//http://localhost:8080/struts2_03/user/useradd?type=1,传个参数type=1
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;
    }

    public String add(){
        return SUCCESS;
    }
}

struts.xml

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <constant name="struts.devMode" value="true" />
    <package name="user" extends="struts-default" namespace="/user">

        <action name="useradd" class="com.struts2_01.user.UserAction" method="add">
        <!--这里result的type类型是redirect,跳转到user_add.jsp,还带着参数t,这里的t应该等于1,如果是result类型是forward,会共享一个值栈。-->
            <result type="redirect">/user_add.jsp?t=${type}</result>
        </action>
     </package>   
</struts>

user_add.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>
from value stack:<s:property value="t"/><!-- 这里的取值为空,因为是跳转到jsp页面,值栈中为空 -->
from Stack Context:<s:property value="#parameters.t"/><!-- 这里可以取到值,因为这里取得是Stack Context中的值 -->
</h1>
<s:debug></s:debug>
</body>
</html>

如图:value stack为空
这里写图片描述

Stack Context有t值
这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值