struts1 flow

在web.xml中配置有
    <servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>




<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>


当页面请求到来时, ActionServlet进行初始化, 执行该Servlet的init()方法,

            initModuleMessageResources(moduleConfig);
initModulePlugIns(moduleConfig);
initModuleFormBeans(moduleConfig);
initModuleForwards(moduleConfig);
initModuleExceptionConfigs(moduleConfig);
initModuleActions(moduleConfig);


完成初始化操作。

之后, 调用该Servlet的doGet 、doPost方法,
    public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
process(request, response);
}
.....


继续方法调用
processor.process(request, response);


其中获取processor方法为:

    /**
* <p>Returns the RequestProcessor for the given module or null if one
* does not exist. This method will not create a RequestProcessor.</p>
*
* @param config The ModuleConfig.
* @return The <code>RequestProcessor</code> for the given module, or
* <code>null</code> if one does not exist.
*/
private RequestProcessor getProcessorForModule(ModuleConfig config) {
String key = Globals.REQUEST_PROCESSOR_KEY + config.getPrefix();

return (RequestProcessor) getServletContext().getAttribute(key);
}



下面简要分析一下上面提及的processor.process(request, response)
public void process(HttpServletRequest request, HttpServletResponse response) {
// 处理文件上传
request = processMultipart(request);
// 得到ActionMapping
ActionMapping mapping = processMapping(request, response, path);
// 得到ActionForm
ActionForm form = processActionForm(request, response, mapping);
// 得到action
Action action = processActionCreate(request, response, mapping);
// 得到forward
ActionForward forward =
processActionPerform(request, response, action, form, mapping);
....
processForwardConfig(request, response, forward);



}

processForwardConfig(request, response, forward) 又会调用RequestDispatcher的forward等方法, 完成
此次转发。



关于action的获取方法 processActionCreate

    protected Action processActionCreate(HttpServletRequest request,
HttpServletResponse response, ActionMapping mapping)
throws IOException {
// Acquire the Action instance we will be using (if there is one)
String className = mapping.getType();

if (log.isDebugEnabled()) {
log.debug(" Looking for Action instance for class " + className);
}

// If there were a mapping property indicating whether
// an Action were a singleton or not ([true]),
// could we just instantiate and return a new instance here?
Action instance;
synchronized (actions) {
// Return any existing Action instance of this class
instance = (Action) actions.get(className);


可见action是单例的
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值