Struts2 一、 视图转发跳转
<struts>
<constant name="struts.118n.encoding" value="UTF-8"></constant>
<constant name="struts.action.extension" value="do"></constant>
<constant name="struts.serve.static.browserCache" value="false"></constant>
<constant name="struts.devMode" value="false"></constant>
<constant name="struts.ui.theme" value="simple"></constant>
1、正常跳转
<pre name="code" class="html"><package name="demo" namespace="/demo" extends="struts-default">
<action name="action_*" class="cn.actions.DemoAction" method="{1}">
<result name="hello">/WEB-INF/pages/message.jsp</result>
</action>
</package>
public class DemoAction {
private String message;
public String toHello() {
this.message = "hello world!";
return "hello";
}
public String getMessage() {
return message;
}
}
访问地址: http://localhost:9000/demo/action_toHello.do
2、默认值跳转
<action name="addUser">
<result>/WEB-INF/pages/addUser.jsp</result>
</action>
访问地址:http://localhost:9000/demo/addUser.do
3、重定向跳转
<pre name="code" class="html"> <!-- 重定向连接 -->
<action name="redirect">
<result type="redirect">/addPerson.jsp</result>
</action>
访问地址:http://localhost:9000/demo/redirect.do
4、带参的重定向跳转
<!-- 重定向连接 带参数-->
<action name="addPeron" class="cn.actions.PersonAction" method="edit">
<result type="redirect">/addPerson.jsp?username=${username}</result>
</action>
public class PersonAction {
private String username;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String edit() throws UnsupportedEncodingException{
this.username=URLEncoder.encode("汤姆","UTF-8");
return "success";
}
}
<body>
<h2>用户名:<%= URLDecoder.decode(new String(request.getParameter("username").getBytes("ISO8859-1"),"UTF-8")) %></h2>
</body>
访问地址:http://localhost:9000/demo/addPeron.do?method=edit
5、重定向Action
<!-- 重定向Action -->
<action name="redirectAction">
<result type="redirectAction">addPeron</result>
</action>
<action name="addPeron" class="cn.actions.PersonAction" method="edit">
<result type="redirect">/addPerson.jsp?username=${username}</result>
</action>
访问地址:http://localhost:9000/demo/redirectAction.do
6、重定向其他包的Action
<package name="demo" namespace="/demo" extends="struts-default">
<!-- 重定向其他包的Action -->
<action name="redirectOtherAction" >
<result type="redirectAction">
<param name="actionName">hello</param>
<param name="namespace">/other</param>
</result>
</action>
</package> <package name="other" namespace="/other" extends="base">
<action name="hello">
<result>/WEB-INF/pages/hello.jsp</result>
</action>
</package>
访问地址:http://localhost:9000/demo/redirectOtherAction.do
7、显示源代码(不执行代码)
<!-- 显示源代码Action(UTF-8编码) -->
<action name="plainText">
<result type="plainText">
<param name="location">/index.jsp</param>
<param name="charSet">UTF-8</param>
</result>
</action>
访问地址:http://localhost:9000/demo/plainText.do
8、包内共享视图
<package name="demo" namespace="/demo" extends="struts-default">
<!-- 包内共用视图 -->
<global-results>
<result name="message">/WEB-INF/pages/message.jsp</result>
</global-results>
<action name="person_*" class="cn.actions.PersonAction" method="{1}">
</action>
</package>
public class PersonAction {
public String save(){
return "message";
}
}
访问地址:http://localhost:9000/demo/person_save.do
9、包外共享视图
Ohter 包继承了 base包 所以可以共享Base包的共享视图
<package name="base" extends="struts-default">
<!-- 包内外共享视图 -->
<global-results>
<result name="message">/WEB-INF/pages/message.jsp</result>
</global-results>
</package>
<package name="other" namespace="/other" extends="base">
<action name="person_*" class="cn.actions.PersonAction" method="{1}">
</action>
</package>
public class PersonAction {
public String save(){
return "message";
}
}
访问地址:http://localhost:9000/other/person_save.do
Struts2 一、 视图转发跳转的更多相关文章
- Struts2中的页面跳转
内容源自:Struts2中的页面跳转 一.全局页面的设置如果<package>包中的一些action都返回success,并且返回的页面都是同一个JSP页面,这样就可以配置全局的结果页面. ...
- Struts2 从一个Action跳至另一个Action
Struts2 从一个Action跳至另一个Action 一.注解的 @Result(name=SUCCESS,type="chain", params={"actio ...
- Struts配置的各种视图转发类型
上面是struts1的视图转发2中类型:1.内部请求转发(来定向到某个视图):2.浏览器重定向(来定向到某个视图). 浏览器重定向(直接访问路径)不能访问WEB-INF的jsp文件,只有服务器内部转发 ...
- myEclipse和eclipse从debug视图自动跳回default视图。
本来是吐槽文,找到了解决的插件,就改改标题了. debug的时候,可以从default视图自动跳转到debug视图,退出debug的时候,却不能自动切换回default视图. https://bugs ...
- UI - 视图控制器跳转另一个视图控制器特效总结
1. 从一个视图控制器跳转另一个视图控制器的方式是可以进行设置的 CATransition *animation = [[CATransition alloc]init]; animation.dur ...
- ios 导航视图控制器 跳转
import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoa ...
- 04. struts2中Result配置的各种视图转发类型
概述 <action name="helloworld" class="com.liuyong666.action.HelloWorldAction"&g ...
- Struts2学习笔记(三):result配置的各项视图转发类型
Struts 1: <action path="/user" type="org.sunny.user.action.UserAction" ...> ...
- struts2 中请求转发与请求重定向方法
本文转自:http://blog.csdn.net/a327736051/article/details/50240491 一.Chain Result:这个result调用另外的一个action,连 ...
随机推荐
- Nginx 配置指令的执行顺序(七)
来看一个 ngx_static 模块服务磁盘文件的例子.我们使用下面这个配置片段: location / { root /var/www/; } 同时在本机的 /var/w ...
- 解决function.bind()方法
这个 bind 方法只有在 ie10 版本的浏览器才得到原生支持,低于该版本的浏览器下执行时会得到一个 undefined 的错误提示. 于是只好再次上网 google 解决方案,功夫不负有心人,我们 ...
- Make a travel blog by Blogabond the theme of wordpress
We can record our place which we have ever went.If you want to know any more you can visit :http://w ...
- MarkDown基础使用教程-by sixleaves
以下是个人浏览文档,结合自己平时使用所总结, 和引用国外关于如何使用markdown的教程.如有不足,还请海涵,期待于您的交流.我觉得使用markdown书写挺好的! 工具下载,可以去下载gitboo ...
- poj 1018 Communication System_贪心
题意:给你n个厂,每个厂有m个产品,产品有B(带宽),P(价格),现在要你求最大的 B/P 明显是枚举,当P大于一定值,B/P为零,可以用这个剪枝 #include <iostream> ...
- 基于winform的二进制图片数据的存取(用于数据库照片的读写处理)
编程目的:文本框1中输入id号,则从openFileDialog中选择的图片会以二进制数据存进SQL数据库的对应表的id列:文本框2中输入姓名,从数据库读取对应name的照片并显示在pictureBo ...
- Unity 之 Redux 模式(第二篇)—— Rigidbody 改造,摄像机控制
作者:软件猫 日期:2016年12月8日 转载请注明出处:http://www.cnblogs.com/softcat/p/6144041.html 上一篇文章中存在一个很严重的问题,首先我们先让 M ...
- eclipse ctrl链接设置
选择[Window]菜单 Preferences ——>General——>Editors——>Text Editors——>Hyperlinking
- OC中NSString 的常用方法
NSString *str1 = @"BeiJing"; NSString *str2 = @"beijing"; //全部转为大写 NSLog(@" ...
- 要删除共享的初始登陆名 cmd下输入net use * /delete
要删除共享的初始登陆名 cmd下输入net use * /delete