配置了sitemesh后用struts2标签就报错

配置了sitemesh后用struts2标签就报错,用ognl El标签却不报错。
原因:sitemesh的过滤器 com.opensymphony.sitemesh.webapp.SiteMeshFilter 应该在
struts2的过滤器 org.apache.struts2.dispatcher.FilterDispatch
(或org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter)之前,在
org.apache.struts2.dispatcher.ActionContextCleanUp过滤器之后
而且ActionContextCleanUp、FilterDispatch(或StrutsPrepareAndExecuteFilter)这两个struts2的过滤器必须得配置

ActionContextCleanUp:延长action中属性的生命周期,包括自定义属性,以便在jsp页面中进行访问,让actionContextcleanup过滤器来清除属性,不让action自己清除。

为了使用WebWork,我们只需要在web.xml配置FilterDispatcher一个过滤器即可,阅读一下FilterDispatcher的 JavaDoc和源码,我们可以看到它调用了:
finally{
ActionContextCleanUp.cleanUp(req);
}

在ActionContextCleanUp中,有这样的代码:
req.setAttribute(CLEANUP_PRESENT, Boolean.TRUE);

如果FilterDispatcher检测到这个属性,就不会清除ActionContext中的内容了,而由 ActionContextCleanUp后续的代码来清除,保证了一系列的Filter访问正确的ActionContext.

如果用到SiteMesh的Filter或者其他类似Filter,那么设置顺序是:

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值