Struts2视图转发
2015-06-10 22:44
429 查看
dispatcher(默认)
<package name="he" namespace="/hello" extends="struts-default"> <action name="h1" class="com.zero.HelloWorldAction" method="execute"> <result name="success">/WEB-INF/jsp/hello.jsp</result> </action> </package>访问http://localhost:8080/Struts2/hello/h1时,浏览器浏览器地址显示http://localhost:8080/Struts2/hello/h1,显示/jsp/hello.jsp的界面。
redirect(浏览器重定向)
<package name="he" namespace="/hello" extends="struts-default"> <action name="h2"> <result type="redirect">/index.jsp</result> </action> </package>访问http://localhost:8080/Struts2/hello/h2时,浏览器地址会重定向到http://localhost:8080/Struts2/index.jsp,显示index.jsp的界面。
redirectAction
<package name="he" namespace="/hello" extends="struts-default"> <action name="h1" class="com.zero.HelloWorldAction" method="execute"> <result name="success">/WEB-INF/jsp/hello.jsp</result> </action> <action name="h3"> <result type="redirectAction">h1</result> </action> </package>访问http://localhost:8080/Struts2/hello/h3时,浏览器地址会重定向到http://localhost:8080/Struts2/hello/h1.action,显示/jsp/hello.jsp的界面。
如果重定向的action不在同一包下:
<package name="he" namespace="/hello" extends="struts-default"> <action name="h3"> <result type="redirectAction"> <param name="actionName">xx</param> <param name="namespace">/xxx</param> </result> </action> </package> <package name="xx" namespace="/xxx" extends="struts-default"> <action name="hh1" class="com.xx.xxx" method="execute"> <result name="success">/WEB-INF/jsp/hello.jsp</result> </action> </package>
plainText(原样显示视图代码)
<package name="he" namespace="/hello" extends="struts-default"> <action name="h4"> <result type="plainText"> <param name="location">/index.jsp</param> <param name="charSet">UTF-8</param><!-- 指定读取文件的编码 --> </result> </action> </package>访问http://localhost:8080/Struts2/hello/h3时,浏览器地址是http://localhost:8080/Struts2/hello/h3,显示index.jsp的源代码。
相关文章推荐
- JavaWeb_Web开发入门
- spring4如何整合 hibernate4 配置详解
- 232_尚学堂_高淇_java300集最全视频教程_【GOF23设计模式】_建造者模式详解
- 小白心目中的Java抽象类(abstract class)
- java基础IO流 Properties类,打印流,合并流
- Spring IOC
- eclipse中查看快捷键
- java PropertyDescriptor 应用及源码分析
- MAC JDK版本切换
- java Introspector谈Java内省机制
- 黑马程序员---2015.6.10java学习笔记---软件--dos--JDK---while
- Java基础
- Java外观模式(Facade)
- 用数组实现栈(java语言实现)
- Spring Aop代理
- Eclipse 生成Android项目javadoc遇到的问题
- 【java】Thread中的同步
- Java笔记02 基础语法1
- Java内部类详解
- Java——(五)Collection之List集合、ArrayList和Vector实现类