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,连 ...
随机推荐
- MYSQL 中的变量
1.用户自己定义变量 2.系统变量(全局变量,会话变量) ----------------------------------------------------------------------- ...
- 使用Hashtable和List结合拼json数据
在做项目的时候,有时候需要向页面返回一个特定的json类型的数据,一般情况下会有下面的方法进行拼接: public String chongzhiList() throws Exception { L ...
- 让Cocos2D-X的示例程序运行起来
没有整理好,现在先标记下 安装好环境后可能遇到的问题: 1.cocos2d-X 2.0版本后创建的Android项目提示org.cocos2dx.lib.Cocos2dxActivity找不到问题 解 ...
- MFC可执行文件问题
MFC生成的.exe可执行文件,在其它机子上无法正常执行.主要是MFC库链接方式的问题,使用MFC分动态连接和静态连接两种: 静态连接就是把需要的MFC库函数放进你的exe之中,这样,在MFC库函 ...
- 线上操作使用tmux提高工作效率
对于常常在线上操作的人来说有一种烦恼,就是在操作过程中,有事离开了一下,电脑自己主动睡眠了.然后网络断开连接.这时候任务就要又一次跑.非常烦恼. tmux能够解决问题. tmux能够看成虚拟屏幕,不受 ...
- iOS7 UIKit动力学-碰撞特性UICollisionBehavior 下
上文讲到了为window加一个边界.实现碰撞的效果,接下来我们将提到一个托付方法: - (void)collisionBehavior:(UICollisionBehavior *)behavior ...
- 最简单也最难——怎样获取到Android控件的高度
问题 怎样获取一个控件的长和高.相信非常多朋友第一眼看见这个问题都会认为非常easy,直接在onCreate里面调用getWidth.getMeasuredWidth不就能够获得了吗,可是.事实上是并 ...
- QImage 与 cv::Mat 之间的相互转换
近期做图像处理方面的项目比較多,非常多算法自己从头写的话太浪费时间,并且自己写的也不一定完好,早就听说OpenCV在图像处理算法方面功能非常强大,一直没时间学习,这次正好项目用到了.暂时抱佛脚学习些O ...
- jQuery 网格布局插件
如今,大多数网站设计要靠网格系统和布局,这能够提供给设计人员一个方便的途径来组织网页上的内容.网格的设计最常见于报纸和杂志的版面,由文字和图像构成的列组成. 这篇文章给大家分享精心挑选的15款最佳的 ...
- string.Format组合跳转路径
string url = this.ResolveClientUrl("~/page/bn_stu.aspx"); string str = string.Format(" ...