Struts2_带参数的结果集
2024-08-25 02:27:36
页面请求:
<a href="user/user?type=1">传参数</a>
action:
public Integer type; public String execute(){
return SUCCESS;
// return "test";
} public Integer getType() {
return type;
} public void setType(Integer type) {
this.type = type;
}
stuts.xml中把type这个参数传到其他的jsp页面:
<action name="user" class="com.bjsxt.struts2.user.action.UserAction">
<!-- $用来在配置文件里面往值栈 valueStack 里取值 -->
<result type="redirect">/user_success.jsp?t=${type}</result>
<result name="test" type="chain">test</result>
</action>
注意:一次request共享一个值栈,要想跨request,比如重定向跳转了,那么就可以通过这种方式传递参数。
jsp页面:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!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=UTF-8">
<title>user_success</title>
<base href="<%=basePath%>"/>
</head>
<body>
<h1>user success.</h1>
值栈中没值,因为是通过参数传过来的,通过redirect的不在同一个request中<br>
from valuestack:<s:property value="t"/><br>
所以只能通过actionContext来取,具体是parameters
from actioncontext:<s:property value="#parameters.t"/>
<s:debug></s:debug>
</body>
</html>
结果:
链接: http://pan.baidu.com/s/1mic8CZm 密码: q5mh
最新文章
- jquery mobile button样式设置
- 安装ESXi5.5遇到Relocating modules and starting up the kernel的处理
- Windows NT驱动程序的基本结构和实例
- 机器人操作系统(ROS)教程4:ROS的框架【转】
- XidianOJ 1097 焊板子的xry111
- Lucene.net入门学习(结合盘古分词)
- 2013 Multi-University Training Contest 3
- iOS开发经验总结(上)
- oracle3
- Android -- getSystemService
- Java客户端Jedis的八种调用方式
- java循环
- POJ-1861-NETWORK 解题报告
- mysql外键
- Zabbix 配置监控主机
- WebService接口定义及调用
- 6.安装pyhook报错is not a supported wheel on this platform
- Js冒泡事件详解及阻止
- bzoj3473字符串&;bzoj3277串
- flex 和bison的安装和使用