<action name="helloworld" class="cn.itcast.action.HelloWorldAction"> <result name="success">/WEB-INF/page/hello.jsp</result> </action>result配置相似于struts1中的forward,但struts2中提供了多种结果类型,经常使用的类型有: dispatcher(默认值)、 redirect(重定向) 、 redirectAction 、 plainText,经过type属性值指定。
一、在result中还能够使用${属性名}表达式访问action中的属性,表达式里的属性名对应action中的属性。以下: jsp
<result type="redirect">/view.jsp?id=${id}</result>
二、下面是redirectAction 结果类型的例子,若是重定向的action在同一个包下: 学习
<result type="redirectAction">helloworld</result>
若是重定向的action在别的命名空间下: 编码
<result type="redirectAction"> <param name="actionName">helloworld</param> <param name="namespace">/test</param> </result>
<result name="source" type="plainText"> <param name="location">/xxx.jsp</param> <param name="charSet">UTF-8</param><!-- 指定读取文件的编码 --> </result>
四、当有多个Action使用同一个结果集时,则能够使用全局结果集(Globle Result),以下: spa
<global-results> <!-- 定义在包里 --> <result name="mainpage">/main.jsp</result> </global-results>
(本学习笔记是根据传智播客的视频教程整理而来) code