Struts2之result的配置

配置<result…/>元素时通常需要指定如下的两个属性:

(1).        name:该属性指定所配置的逻辑视图

(2).        type:该属性指定结果类型

  <struts>
	<package name="owen" extends="struts-default">
		<action name="resultAction" class="com.owen.action.LoginRegistAction">
       <!—dispatcher就是转到指定的页面,它与direct有区别在后续讲解-->
			<result
 name=”success” result=”dispatcher”>/WEB-INF/content/welcome.jsp</result>
		</action>
		<action name="*">
			<result>/WEB-INF/content/{1}.jsp</result>
		</action>
	</package>
</struts>

1. redirect和redirectAction结果类型

1.1 redirect结果类型

dispatcher结果类型与redirect结果类型相对,dispathcer结果类型是将请求forward(转发)到指定的JSP资源;而redirect结果类型,则意味着将请求redirect(重定向)到指定的视图资源。dispatcher结果类型与redirect结果类型的差别主要是转发和重定向的差别:重定向会丢失所有的请求参数、请求属性也丢失了Action的处理。

<struts>
	<constant name="struts.devMode" value="true"/>
	<package name="lee" extends="struts-default">
		<action name="login" class="com.owen.action.LoginAction">
			<!-- 指定结果的类型为redirect,
				这意味着系统该Action将重定向到welcome.jsp页面-->
			<result type="redirect">/welcome.jsp</result>
		</action>
		<action name="*">
			<result>/WEB-INF/content/{1}.jsp</result>
		</action>
	</package>
</struts>

1.2 redirectAction结果类型

这种结果类型与redirect类型非常相似,一样是新生成一个全新的请求。但redirectAction使用ActionMapperFactory提供的ActionMapper来重定向请求。

配置redirectAction结果类型时,可以指定如下的参数:

(1).        actionName:该参数指定重定向的Action名

(2).        namespace:该参数指定需要重定向的Action所在的命名空间。

<struts>
	<constant name="struts.devMode" value="true"/>
	<package name="lee" extends="struts-default">
		<action name="login" class="com.owen.action.LoginAction">
			<result type="redirectAction">
                 <param name=”actionName”>owen</param>
                 <param name=”namespace”>/secure</param>
</result>
		</action>
		<action name="*">
			<result>/WEB-INF/content/{1}.jsp</result>
		</action>
	</package>
<package name=" secure " extends="struts-default" namespace=”/ secure”>
		<action name=" owen " class="com.owen.action.Owen">
			<result type="redirectAction"> owen .jsp</result>
		</action>
	</package>

</struts>




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值