配置了sitemesh后用struts2标签就报错
  zw77MQd1kOsI 2023年11月02日 65 0


配置了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

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
zw77MQd1kOsI