博客
关于我
struts 2中的chain
阅读量:142 次
发布时间:2019-02-26

本文共 780 字,大约阅读时间需要 2 分钟。

 struts2 中的一大特点就是拦截器,特别是拦截器可以组成拦截链,一篇很好的介绍文章可以辅助学习之,推荐之这里

 

这里结合项目中的具体来个感性认识:

 比如在购物车的时候,一个典型的场景为当用户在一个购物车选择时,如果要把物品从购物车中删除,删除后其实是继续显示当前的购物车的,

但只不过是购物车里的物品少了一件,因此可以这样去处理:

  首先是 删除商品的控制器所对应的xml配置文件如下
   <!-- This action 负责将用户不需的商品从购物车删除 -->
    <action  name="deletefromcart" class="eshop.action.DeletefromCart">
    <interceptor-ref name="completeStack"></interceptor-ref>
     <result name="success" type="chain">displaycart</result>
     <result name="error" >error.html</result>
    </action>

当删除成功后,其中用type=chain的拦截器,指定让其去执行displaycart的控制器,

 <action name="displaycart" class="eshop.action.DisplayCart">
     <interceptor-ref name="completeStack"></interceptor-ref>
     <result name="success" type="velocity>ShoppingCart.vm</result>
     <result name="error" >error.html</result>
    </action>

 而这个displaycart的控制器其实就是刷新显示了当前的购物车了

转载地址:http://doif.baihongyu.com/

你可能感兴趣的文章
nginx+vsftp搭建图片服务器
查看>>
Nginx-http-flv-module流媒体服务器搭建+模拟推流+flv.js在前端html和Vue中播放HTTP-FLV视频流
查看>>
nginx-vts + prometheus 监控nginx
查看>>
Nginx/Apache反向代理
查看>>
Nginx: 413 – Request Entity Too Large Error and Solution
查看>>
nginx: [emerg] getpwnam(“www”) failed 错误处理方法
查看>>
nginx: [emerg] the “ssl“ parameter requires ngx_http_ssl_module in /usr/local/nginx/conf/nginx.conf:
查看>>
nginx: [error] open() “/usr/local/nginx/logs/nginx.pid“ failed (2: No such file or directory)
查看>>
nginx:Error ./configure: error: the HTTP rewrite module requires the PCRE library
查看>>
Nginx:objs/Makefile:432: recipe for target ‘objs/src/core/ngx_murmurhash.o‘解决方法
查看>>
nginxWebUI runCmd RCE漏洞复现
查看>>
nginx_rtmp
查看>>
Vue中向js中传递参数并在js中定义对象并转换参数
查看>>
Nginx、HAProxy、LVS
查看>>
nginx一些重要配置说明
查看>>
Nginx下配置codeigniter框架方法
查看>>
Nginx与Tengine安装和使用以及配置健康节点检测
查看>>
Nginx中使用expires指令实现配置浏览器缓存
查看>>
Nginx中使用keepalive实现保持上游长连接实现提高吞吐量示例与测试
查看>>
Nginx中如何配置WebSocket代理?
查看>>