`
ldzyz007
  • 浏览: 699935 次
  • 性别: Icon_minigender_1
  • 来自: 西安
社区版块
存档分类
最新评论

配置了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
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics