<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. Nginx 配置指令的执行顺序(十)

    运行在 post-rewrite 阶段之后的是所谓的 preaccess 阶段.该阶段在 access 阶段之前执行,故名preaccess. 标准模块 ngx_limit_req 和 ngx_lim ...

  2. Servlet中Web.xml的配置详解

    1 定义头和根元素 部署描述符文件就像所有XML文件一样,必须以一个XML头开始.这个头声明可以使用的XML版本并给出文件的字符编码. DOCYTPE声明必须立即出现在此头之后.这个声明告诉服务器适用 ...

  3. 生成war的jdk版本高于tomcat使用的jdk版本,导致项目不能正常被访问

    记录一个耽误30分钟的一个坑: 生成war的jdk版本高于tomcat使用的jdk版本,导致项目不能正常被访问 报404错误

  4. javascript链式调用实现方式总结

    方法链一般适合对一个对象进行连续操作(集中在一句代码).一定程度上可以减少代码量,缺点是它占用了函数的返回值. 一.方法体内返回对象实例自身(this) function ClassA(){ this ...

  5. 快速配置 Samba 将 Linux 目录映射为 Windows 驱动器

    原文链接 samba client ubuntu redhat ubuntu gui tools 1,列出某个IP地址所提供的共享文件夹 smbclient -L 198.168.0.1   2,在s ...

  6. 在MFC下实现图像放大镜

    当我们想仔细观察某个细微的东西时,一般都会使用放大镜.而要看清显示在计算机屏幕上的图片或文字时通常也可以借助于Windows操作系统附带的放大程序来实现.但该程序只能以固定的放大倍数去进行观看,有时并 ...

  7. cf467C George and Job

    C. George and Job time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  8. JIRA官方:JIRA亮点介绍

    操作超级简单 简单不意味着要以牺牲功能作为代价.JIRA提供了友好.直观的可配置的Web界面,并支持大量的快捷键操作. 跟踪任何事务 跟踪问题.任务.需求,当然还有软件缺陷.定义你自己的事务类型来使之 ...

  9. Javascript数组操作方法

    1.shift:删除原数组第一项,并返回删除元素的值:如果数组为空则返回undefined var a = [1,2,3,4,5]; var b = a.shift(); //a:[2,3,4,5] ...

  10. MediaInfo使用简介(新版本支持HEVC)

    MediaInfo 用来分析视频和音频文件的编码和内容信息,是一款是自由软件 (免费使用.免费获得源代码).他除了提供DLL之外,本身也提供GUI工具用于查看视频信息.我使用中发现,新版本的Media ...