您的位置:首页 > 编程语言 > Java开发

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的源代码。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: