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 配置指令的执行顺序(六)
前面我们在 (五) 中提到,在一个 location 中使用 content 阶段指令时,通常情况下就是对应的 Nginx 模块注册该 location 中的“内容处理程序”.那么当一个 locati ...
- 解析XML【C#】
1.XML元素XML元素包含一个开标记.元素中的数据.闭标记例如:<book>book name</book>其中book是元素名称 book name是元素数据元素名称区 ...
- cdoj 491 Tricks in Bits
//无脑爆居然能过!!!!! 解:其实正解也是暴力,但是可以证明在n>6时答案一定为零. 第一步:对于任意两个数他们的二进制数要么有一半+的位是相同的,要么有一半+的位是不同的,于是首先使用与运 ...
- linux学习方法之六
相信不少想学习linux的新手们正愁不知道看什么linux学习教程好,下面小编给大家收集和整理了几点比较重要的教程,供大家学习,如需想学习更多的话,可到wdlinux学堂寻找更多教程. 1.linux ...
- redhat5安装jdk6、eclipse和tomcat6
redhat5安装jdk6.eclipse和tomcat6 1.安装jdk6 首先下载jdk(jdk-6u13-linux-i586.bin),对于redhat5,本人强烈建议不要安装jdk7,因为有 ...
- js原生 + jQuery实现页面滚动字幕
js原生/jQuery实现页面滚动字幕效果 17:45:49 在新闻列表或者文章列表信息等页面中很容易要求实现字幕滚动的效果,以下为简单的实现页面中滚动字幕的效果 1.jQuery实现页面滚动字幕效果 ...
- hdu 4496 D-City(并查集)
Problem Description Luxer is a really bad guy. He destroys everything he met. One day Luxer went to ...
- 使用 fastlane 实现 iOS 持续集成(转)
http://www.cocoachina.com/ios/20150916/13433.html 简介 持续集成是个“一次配置长期受益”的工作.但很多小公司都没有.以前在做Windows开发配置感觉 ...
- 为什么VS提示SurfFeatureDetector不是cv的成员函数
surf和sift算法都是在头文件#include <opencv2/features2d/features2d.hpp>中,但在新的opencv版本出来后,如果仍然使用这个头文件就会出现 ...
- HDU2054_A == B ?【模拟题】【大数】【水的问题】
A == B ? Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total S ...