读书人

struts1.3 amp; struts 1.2 RequestPr

发布时间: 2012-11-20 09:55:43 作者: rapoo

struts1.3 & struts 1.2 RequestProcessor区别
struts1.2.9 ==============================

ActionServlet:

请求dopost或doget调用: protected void process(HttpServletRequest request, HttpServletResponse response)        throws IOException, ServletException {        ModuleUtils.getInstance().selectModule(request, getServletContext());        ModuleConfig config = getModuleConfig(request);        RequestProcessor processor = getProcessorForModule(config);        if (processor == null) {           processor = getRequestProcessor(config);        }//在1.2.9中使用RequestProcessor 实例        processor.process(request, response);    }  //第一次请求到来时调用 protected synchronized RequestProcessor getRequestProcessor(ModuleConfig config)        throws ServletException {    RequestProcessor processor = this.getProcessorForModule(config);    if (processor == null) {            try {                processor =                    (RequestProcessor) RequestUtils.applicationInstance(                        config.getControllerConfig().getProcessorClass()); 。。。。} 

=====================================================
ActionServlet.init()
的 moduleConfig.freeze()方法
由子类ModuleConfigImpl.class实现
  getControllerConfig().freeze(); public ControllerConfig getControllerConfig() {        if (this.controllerConfig == null) {            this.controllerConfig = new ControllerConfig();        }        return (this.controllerConfig);    }

在ControllerConfig中有:
protected String processorClass =
"org.apache.struts.action.RequestProcessor";

所以在上面
ActionServlet的getRequestProcessor方法中返回的是org.apache.struts.action.RequestProcessor并创建实例

======================================================
而1.3.10中
ControllerConfig改为:
protected String processorClass =
"org.apache.struts.chain.ComposableRequestProcessor";
所以实际使用ComposableRequestProcessor类处理struts流程
=================================================

可以在struts-config.xml中添加:
<controllerprocessor/>
指定RequestProcessor处理。

读书人网 >软件架构设计

热点推荐