struts2 action以及页面跳转
来源:互联网 发布:js 判断是否为数组 编辑:程序博客网 时间:2024/06/05 17:39
一、页面跳转
1. struts2中从WEB-INF下的页面直接超链接到WebRoot目录下的页面,
jsp页面中可以设置如下:
假设当前路径为http://127.0.0.1:8088/LYDF/department/departmentList.action,执行超链接“HomePate”后跳转到http://127.0.0.1:8088/LYDF/main.jsp路径,即WebRoot目录下main.jsp页面。
<a href="main.jsp">HomePage</a>
<a href="${pageContext.request.contextPath}/main.jsp">HomePage</a>,
两种写法会达到同样的效果。
2. 当希望通过点击按钮或超链接后直接跳转到一个指定页面时,页面设置可以如下:
<input type="button" onclick="location='toAdd.action'" value="添加"/>
或<a href="toAdd.action">添加</a>
配置文件struts.xml中可以设置如下:
<package name="department" extents="struts-default">
<action name="toAdd">
<result>/WEB-INF/department/department_add.jsp</result>
</action>
...
</package>
此处, action 不写class和 method ,result 不写 name 。
二、action跳转
action之间的跳转,是通过指定result的类型,实现的。
(1)type="dispatcher" 为默认,用于jsp页面跳转
<result name="success">/index.jsp</result>
完整的写法为:
<result name="success" type="dispatcher">
<param name="location">/index.jsp</param>
</result>
(2)type="redirect" 重定向到jsp、action、外部网址
<result name="success" type="redirect">/index.jsp</result>
<result name="success" type="redirect">/login.do</result>
<result name="success" type="redirect">http://www.baidu.com</result>
type="redirect" 重定向是把一个http返回码(SUCCESS)以及返回的页面位置重新发给服务器,由web服务器产生一个新的HTTP请求,产生新的线程,保存在原Action中的数据无法访问。如果需要访问,则在action中带参数,参数为一个OGNL表达式,此时该变量必须在前action中有set/get方法,使用${变量名}即可访问到该数据。
参数之间必须使用& 。&是&在xml中转义字符
重定向时带参数处理方法:
1.type="redirect":
<result name="success" type="redirect">/login.do?userId=${userId }&name=${userName }</result>
2.type="redirect-action":
见(3)
(3)type="redirect-action" 重定向到另外一个action
<result name="success" type="redirect-action">
<param name="actionName">login.do</param> // 重定向action名
<param name="userId">userId</param> //带的参数
<param name="name">userName</param>
</result>
(4)type="chain" 用于action跳转。
用于把相关的几个action连接起来,共同完成一个功能。处于chain中的action属于同一个http请求,共享一个ActionContext。所以仍可以在跳转后的action中通过获取ActionContext获取request。
<action name="action1" class="org.Action1">
<result name="success" type="chain">action2.do</result>
</action>
<action name="action2" class="org.Action2">
<result name="success">login.jsp</result>
</action>
若action不在同一个package下,需要配置命名空间这个参数。如下
(5)type="plaintextj" 跳转显示源代码
<result name="err" type="plaintext">
<param name="location">具体的位置</param>
<param name="charSet">字符规范(如GBK)</param>
</result>
- struts2 action以及页面跳转
- struts2 action 页面跳转
- [struts2]struts2 action 页面跳转
- struts2 action 页面跳转,有两个跳转类型是亲试过
- struts2 配置 jquery ajax 调用 action 跳转页面
- struts2[杂记] action跳转action
- Struts2 Action中跳转Action
- Struts2 Action中跳转Action
- struts2 action跳转到action
- struts2 action跳转指向action
- struts2 action 之间跳转
- struts2 action 之间跳转
- struts2 action跳转
- struts2 action 之间跳转
- Struts2之Action跳转
- struts2 Action之间跳转
- struts2 Action之间跳转
- 使用action页面跳转
- 一张图读懂互联网大咖
- owin学习笔记(1)
- 泛型程序设计
- Instruments(转载)
- Android_如何获取Android唯一标识(唯一序列号)
- struts2 action以及页面跳转
- JAVA中calendar,date,string 的相互转换和详细用法
- 调试工具之GDB
- ARC Welder——Android 模拟器——App Runtime for Chrome
- caffe 实例笔记 4 Multilabel classification on PASCAL using python data-layers
- 关于Android开发大神的博客汇总
- Android面试题积累一
- jquery 判断selection range 是否在容器中
- java中堆和栈的区别,递归和迭代的区别