struts2 FilterDispatcher

来源:互联网 发布:环球国际软件下载 编辑:程序博客网 时间:2024/04/30 05:14
1:在FilterDispatcher 类中有属性
  private static boolean serveStatic;
 private static ActionMapper actionMapper;
这两个属性通过容器Container进行注入的
struts-default.xml中有<bean class="org.apache.struts2.dispatcher.FilterDispatcher" static="true" />这样一句
就是注入static 属性.
然后在doFilter方法中去找访问的url有没有相应的ActionMapping(存放Action的)
如果没有的话再去找静态资源,在init方法中有        
String packages = "org.apache.struts2.static template org.apache.struts2.interceptor.debugging";
也可以自己在web.xml中配置packages属性
然后就可以在浏览器中  访问处于org.apache.struts2.static,template,org.apache.struts2.interceptor.debugging
,web.xml中配置packages属性下访问资源,但是uri要以struts开始
比如我要访问org.apache.struts2.static下的optiontransferselect.js(jar文件解压就能看见)
/struts/optiontransferselect.js就能下载这个js
 
 
2:
finally {            try {                ActionContextCleanUp.cleanUp(req);            } finally {                UtilTimerStack.pop(timerKey);            }        }
 
ActionContextCleanUp的doFilter方法
finally {                int counterVal = ((Integer)request.getAttribute(COUNTER)).intValue();                counterVal -= 1;                request.setAttribute(COUNTER, new Integer(counterVal));                cleanUp(request);        }
ActionContextCleanUp的cleanUp方法清理资源
ActionContext.setContext(null);Dispatcher.setInstance(null);