一,result的type类型
<action name="hello" class="com.thridProject.action.HelloAction">
<result type="dispatcher" name="success">/hello.jsp</result>
<result type="redirect" name="success">/hello.jsp</result>
</action>
<action name="r2">
<result type="chain" name="success">hello</result>
<result type="redirectAction" name="success">hello</result>
</action>
通常最常用的四种类型,当然还有freemarker类型,不在阐述。
我们都知道在页面跳转还有两种方式,服务器跳转和浏览器重新发送跳转。(forward和redirect)
dispatcher是默认的类型,是服务器forward类型跳转,不过跳转的页面必须是jsp或者html的页面类型
redirect是浏览器重发跳转,跳转到额页面必须是jsp或者是html的类型,也可以是action
所以另两个就不难理解了,都是action跳转,其中chain是服务器action跳转,而redirectAction就是redirect类型的action跳转了。
二、redirect和redirectAction chain的区别struts2中关于result的返回类型一般我们是转发到一个jsp页面或者是html页面等,但是struts2中的result的返回类型还有redirect,redirectAction,chain。对于这三种返回类型之间肯定是有区别的,下面我们来看看关于redirect redirectAction chain这三种struts2的返回类型之间的区别。当使用type=“redirectAction” 或type=“redirect”提交到一个action并且需要传递一个参数时。这里是有区别的:使用type=“redirectAction”时,结果就只能写Action的配置名,不能带有后缀:“.action”使用type=“redirect”时,结果应是action配置名+后缀名
1.redirect:action处理完后重定向到一个视图资源(如:jsp页面),请求参数全部丢失,action处理结果也全部丢失。
2.redirect-action:action处理完后重定向到一个action,请求参数全部丢失,action处理结果也全部丢失。
3.chain:action处理完后转发到一个action,请求参数全部丢失,action处理结不会
三、Global-results配置,可以实现多个result,但在当前包中action的result中没有找到result时会调用
<global-results>
<result name="">/xxxx.jsp</result>
<result name=
</global-results>
四、动态result实现
1)我们前面有一种使用通配符动态的为result来实现动态页面的跳转
2)中我们可以使用${}其中大括号可以是action中定义的属性值,可以去值栈中的值来配置result
3)也可以通过${}来动态的传参
五、声明异常
1)可以对action执行发现的异常进行捕捉,并且跳转到异常页面,这个时候的Struts.xml的配置为:
<action name="hello" class="com.thridProject.action.HelloAction">
<result type="dispatcher" name="success">/hello.jsp</result>
<exception-mapping result="error" exception="Exception类型"></exception-mapping>
<result name="error">/error.jsp</result>
</action>
2)
同样也存在Gloable-exception-mapping,同时Gloable-result必须写在Gloable-exception-mapping前面。
3)使用继承其他包来实现异常异常的共同处理
4)异常的实现以及Struts功能的实现大多数都是由于Struts存在了拦截器的效果, 这个拦截器就跟filter差不多,我们也可以定义自己的拦截器,但是我们定义了自己的拦截器,然后再使用时,最好加上原本的struts默认的拦截器,这样才能保证struts的全部功能。
分享到:
相关推荐
添加如下内容 --> <result-types> <result-type name="streamx" class="com.sunspoter.lib.web.struts2.dispatcher.StreamResultX"/> </result-types> <action name="download" class="com.DownloadAction"> <...
Struts2和Struts1的常见区别 二. Struts2入门 3. 快速配置Struts2环境 4. 开发一个Struts2简单实例 5. struts.xml文件 三. Struts2深入开发 6. 常用标签配置和使用 7. 常用<result>标签配置和使用 8....
type : result类型 不写则选用superpackage的type struts-default.xml中的默认为dispatcher --> <result name="success" type="dispatcher">/talk.jsp</result> <!-- 参数设置 name:对应Action中...
<result name="IOException" >/error/ioexception.jsp</result> <result name="SQLException" >/error/sqlexception.jsp</result> </global-results> <global-exception-mappings> <exception-mapping result=...
<package name="default" namespace="/" extends="struts-default"> <global-results> <result name="error">/error.jsp</result> </global-results> <global-exception-mappings> <exception-mapping ...
<package name="mySturtsInterceptor" extends="struts-default"> <interceptor name="MyInterceptor" class="com.cn.system.interceptor.MyInterceptor"></interceptor> <interceptor-stack name=...
DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"> <struts-config> <data-sources /> <form-beans > ...
<package name="struts2" extends="struts-default"> <global-results> <result name="add_success" type="redirect">/common/pub_add_success.jsp</result> <result name="del_success" type="redirect...
-- 更改struts2请求Action的后缀名,默认为action。若想去掉后缀,设为","即可 --> <constant name="struts.action.extension" value=","/> <!-- 当配置文件修改后,系统自动加载该文件。开发阶段建议打开此功能...
2、拦截器不依赖于servlet容器,通过动态代理实现,过滤器依赖于servlet容器 3、拦截器在方法前后,异常前后等调用,而过滤器只能在请求前和请求后各调一次。 4、拦截器可以利用依赖注入,因此在spring框架程序中,...
struts json 类型异常返回到js弹框问题解决办法 当struts 框架配置了异常时 例如: <package name=sysCnn namespace=/ extends=json-default> <global> <result name=error>/WEB-INF/pages/error.jsp</result> ...
│ struts.xml │ ├─28个java常用的工具类 │ │ Base64.java │ │ Base64DecodingException.java │ │ CConst.java │ │ CharTools.java │ │ ConfigHelper.java │ │ Counter.java │ │ CTool.java │ │...
2. 深入 STRUTS架构..................................................................................37 2.1. 随便谈谈......................................................................................
2. 深入STRUTS 架构..................................................................................37 2.1. 随便谈谈.......................................................................................