struts2的resultType类型
2014-01-05 17:25
316 查看
常用的resultType类型
chain转发到action
dispatcher转发到jsp界面
redirect重定向到jsp
redirectAction重定向到action
stream用于文件下载
==========================================
dispatcher转发到jsp界面
重定向到jsp的底层代码:
重定向到Action redirectAction
chain转发到action
dispatcher转发到jsp界面
redirect重定向到jsp
redirectAction重定向到action
stream用于文件下载
==========================================
dispatcher转发到jsp界面
<package name="type" namespace="/" extends="struts-default"> <action name="result" class="com.struts.resultype.ResultTypeAction"> <!-- result标签当中 name:的默认值为success type的默认值为转发dispatcher,转发到jsp --> <result name="success" type="dispatcher"> <param name="location">/type.jsp</param> </result> </action> </package>转发底层主要代码:
public class ServletDispatcherResult extends StrutsResultSupport { public void doExecute(String finalLocation, ActionInvocation invocation) throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); RequestDispatcher dispatcher = request.getRequestDispatcher(finalLocation); dispatcher.forward(request, response); } } public void setLocation(String location) { this.location = location; }redirect重定向到jsp:
<package name="type" namespace="/" extends="struts-default"> <action name="result" class="com.struts.resultype.ResultTypeAction"> <result name="success" type="redirect"> <param name="location">/type.jsp</param> </result> </action> </package>
重定向到jsp的底层代码:
public class ServletRedirectResult extends StrutsResultSupport implements ReflectionExceptionHandler { protected void doExecute(String finalLocation, ActionInvocation invocation) throws Exception { HttpServletRequest request = (HttpServletRequest) ctx.get(ServletActionContext.HTTP_REQUEST); HttpServletResponse response = (HttpServletResponse) ctx.get(ServletActionContext.HTTP_RESPONSE); sendRedirect(response, finalLocation); } protected void sendRedirect(HttpServletResponse response, String finalLocation) throws IOException { response.sendRedirect(finalLocation); } } public void setLocation(String location) { this.location = location; }
重定向到Action redirectAction
<package name="type" namespace="/" extends="struts-default"> <action name="result" class="com.struts.resultype.ResultTypeAction"> <!-- 第一种写法--> <result name="success" type="redirectAction"> login </result> <!--第二种写法--> <result name="success" type="redirectAction"> <!--namespace值为package当中的namespace名称 actionName为定义的action当中的name名称--> <param name="namespace">/</param> <param name="actionName">login</param> </result> </action> </package>
相关文章推荐
- struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
- struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
- struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)_forever
- 2011-02-25 12:23 struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
- struts2中result的type跳转类型
- struts2 跳转类型介绍 result type=chain、dispatcher、redirect(redirect-action)
- struts2由浅入深专题分享——result-types 第一回 result-type类型及常见的几个类型 by:丹恋耗
- struts2中result的type跳转类型
- struts2 跳转类型 result type=chain、dispatcher、redirect
- struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
- Struts2 result type(结果类型)
- Struts2 result type(结果类型)
- struts2 result type类型
- struts2中result的type跳转类型总结
- Struts2中的结果类型_result_type
- Struts2 result type(结果类型)
- Struts2 result type(结果类型)
- struts2中常用Result类型(type)的用法
- struts2 跳转类型 result type=chain、dispatcher、redirect(redirect-action)
- struts2跳转类型result type=chain/dispatcher/redirect