Process flow of progressive Struts1 (v) in layers

Source: Internet
Author: User
Tags config log

This blog we go into the struts framework to execute part of the source code, starting from the Actionservlet process function, look at its internal implementation process.

Flow chart

The following flowchart shows the functions used by the Actionservlet and requestprocessor two classes, such as functions of other classes called by Requestprocessor.

Function description

We choose several important function descriptions, and other functions are simply explained.

Actionservlet

Process

/** 
* <p>perform the standard request processing for this request, and create
* the CORRESPO nding response.</p>
*
* @param request the servlet request we are processing
* @param res Ponse The servlet response we are creating
*
* @exception IOException If an input/output error occurs * @exception servletexception If a servlet exception is thrown
*/protected void process (Httpservletreque St request, httpservletresponse Response)
throws IOException, servletexception {
Moduleutils.getinst Ance (). Selectmodule (Request, Getservletcontext ());
Moduleconfig config = getmoduleconfig (request);
Requestprocessor processor = getprocessorformodule (config);
if (processor = null) {
Processor = getrequestprocessor (config);

Processor.process (request, response);
}
}

When debugging first enters this function (Tomcat starts up, produces the request), this function is obtains the loading phase to produce the module object, produces the struts logical processing main object requestprocessor.

Requestprocessor

Process

/**
* <p>process an <code>HttpServletRequest</code> Create the
* Corresponding <code>HttpServletResponse</code> or dispatch
* to another resource.</p>
*
* @param request the servlet request we are processing
* @param response The servlet response we are creating
*
* @exception IOException If an input/output error occurs
* @exception servletexception If a processing exception occurs
* * public void process (HttpServletRequest request,
HttpServletResponse response)
Throws IOException, Servletexception {
Wrap multipart requests with a special wrapper
Request = Processmultipart (request);
Identify the path component we use to select a mapping
String Path = Processpath (request, response);
if (path = = null) {
Return
}
if (log.isdebugenabled ()) {
Log.debug ("Processing a '" + request.getmethod () +
"' For path '" + Path + "" ");
}
Select a Locale for the current user if requested Processlocale (request, response);
Set the content type and no-caching headers if requested
ProcessContent (request, response);
Processnocache (request, response);
General purpose preprocessing Hook
if (!processpreprocess (request, response)) {
Return
}
This.processcachedmessages (request, response);
Identify the mapping for this request
actionmapping mapping = processmapping (request, response, path);
if (mapping = = null) {
Return
}
Check for no role required to perform this action
if (!processroles (request, response, mapping)) {
Return
}
Process any actionform beans related to this request
Actionform form = processactionform (request, response, mapping);
Processpopulate (Request, response, form, mapping);
Validate any fields of the actionform bean, if applicable
try {
if (!processvalidate (Request, response, form, mapping)) {
Return
}
catch (Invalidcancelexception e) {
Actionforward forward = processexception (request, response, E, form, mapping);
Processforwardconfig (Request, response, forward);
Return
catch (IOException e) {
Throw e;
catch (Servletexception e) {
Throw e;
}
Process a forward or include specified by this mapping
if (!processforward (request, response, mapping)) {
Return
}
if (!processinclude (request, response, mapping)) {
Return
}
Create or acquire the Action instance to process this request
Action action = processactioncreate (request, response, mapping);
if (action = null) {
Return
}
Call the Action instance itself
Actionforward forward =
Processactionperform (Request, Response,
Action, form, mapping);
Process The returned Actionforward instance
Processforwardconfig (Request, response, forward);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.