<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 一、 视图转发跳转的更多相关文章

  1. Struts2中的页面跳转

    内容源自:Struts2中的页面跳转 一.全局页面的设置如果<package>包中的一些action都返回success,并且返回的页面都是同一个JSP页面,这样就可以配置全局的结果页面. ...

  2. Struts2 从一个Action跳至另一个Action

    Struts2  从一个Action跳至另一个Action 一.注解的 @Result(name=SUCCESS,type="chain", params={"actio ...

  3. Struts配置的各种视图转发类型

    上面是struts1的视图转发2中类型:1.内部请求转发(来定向到某个视图):2.浏览器重定向(来定向到某个视图). 浏览器重定向(直接访问路径)不能访问WEB-INF的jsp文件,只有服务器内部转发 ...

  4. myEclipse和eclipse从debug视图自动跳回default视图。

    本来是吐槽文,找到了解决的插件,就改改标题了. debug的时候,可以从default视图自动跳转到debug视图,退出debug的时候,却不能自动切换回default视图. https://bugs ...

  5. UI - 视图控制器跳转另一个视图控制器特效总结

    1. 从一个视图控制器跳转另一个视图控制器的方式是可以进行设置的 CATransition *animation = [[CATransition alloc]init]; animation.dur ...

  6. ios 导航视图控制器 跳转

    import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoa ...

  7. 04. struts2中Result配置的各种视图转发类型

    概述 <action name="helloworld" class="com.liuyong666.action.HelloWorldAction"&g ...

  8. Struts2学习笔记(三):result配置的各项视图转发类型

    Struts 1: <action path="/user" type="org.sunny.user.action.UserAction" ...> ...

  9. struts2 中请求转发与请求重定向方法

    本文转自:http://blog.csdn.net/a327736051/article/details/50240491 一.Chain Result:这个result调用另外的一个action,连 ...

随机推荐

  1. SQL Server dbcc shrinkfile 不起作用

    方法 1.重建聚集索引. 方法 2.重建堆表. ---------------------------------------------------------------------------- ...

  2. Dynamics CRM 2013 初体验(3):新增加的功能

    新系统除了修补系统历史漏洞外当然还会添加些比较有意思的新功能,至于这些新功能是否好用那就得看它是否能经过咱们这些使用者的考验了.Dynamics CRM 2013系统将不再支持Dynamics CRM ...

  3. 【LeetCode练习题】Permutations

    全排列 Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the fo ...

  4. 模板应用--UI线程与worker线程同步 模仿c# invoke

    由之前的一篇博文 <UI线程与worker线程><UI线程与worker线程>引出,UI线程与worker线程“串行化”在win32上实现是多么没有节操的事情,代码编写麻烦不说 ...

  5. FTP的主动模式和被动模式

    摘自http://blog.csdn.net/love_gaohz/article/details/50723164 http://my.oschina.net/binny/blog/17469 FT ...

  6. 使用ashx一般处理程序,读取不到Session的问题

    一般的处理程序文件里面是用不了Session的,必须得实现Session接口才可以用. public class RandomCode : IHttpHandler, System.Web.Sessi ...

  7. Fire Net(dfs)

    Fire Net Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  8. Swift中的集合类型

    一.引子: 在2014年10月TIOBE编程语言排行榜中,Swift位居第18位,从2014WWDC发布会首次公布至今不到半年时间,swift一直受到编程人 员的追捧,其热衷程度并不亚于当红巨星Tay ...

  9. WPF做的迁移文件小工具

    客户这边需要往服务器上传PDF文件.然后PDF文件很多,需要挑出来的PDF文件也不少.因此做了个小工具. 功能很简单,选定源文件夹,选定记录着要提取的文件的excel 文件.OK ,界面如下. XAM ...

  10. think in python 11 字典

    字典 字典类似于列表,但更加通用 键值对 ,字典是 键与值之间的映射,每个键都映射到一个值上 dict可以创建一个不包含任何项的字典 eng2sp = dict() print eng2sp 还可以给 ...