Deep analysis of webwork file uploading mechanism in Java

Source: Internet
Author: User

After clicking the Upload button, the WebWork program flow is as follows:

Step 1) into the Servletdispatcher.service

public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException {
........
request = wrapRequest(request);
.........
}

STEP2) into the Servletdispatcher.wraprequest

protected HttpServletRequest wrapRequest(HttpServletRequest request)
throws IOException {
........................
if (MultiPartRequest.isMultiPart(request)) {
request = new MultiPartRequestWrapper(request, getSaveDir(), getMaxSize());
}
return request;
}

STEP3) Construction method of entering Multipartrequestwrapper

public Multipartrequestwrapper (httpservletrequest request, String savedir, int maxSize)
throws IOException {
.......... .... ...
//step3.1) Gets the webwork.preperties configured parser
String parser = "";
Parser = configuration.getstring ("Webwork.multipart.parser");
//If it isn't set, use Pell
If (Parser.equals ("")) {
Log.warn ("Property Webwork.multipart.parser not set." +
Using com.opensymphony.webwork.dispatcher.multipart.PellMultiPartRequest);
Parser = "Com.opensymphony.webwork.dispatcher.multipart.PellMultiPartRequest";
}
//Legacy support for Old style property values
Else if (parser.equals ("Pell")) {
Parser = "Com.opensym Phony.webwork.dispatcher.multipart.PellMultiPartRequest ";
} else if (parser.equals ("cos")) {
Parser = " Com.opensymphony.webwork.dispatcher.multipart.CosMultiPartRequest ";
} else if (Parser.equals ("Jakarta")) {
Parser = " Com.opensymphony.webwork.dispatcher.multipart.JakartaMultiPartRequest ";

//step3.2) instantiating parser
try {
Class Baseclazz =
after fetching Com.opensymphony.webwork.dispatcher.multipart.MultiPartRequest.class;
Class clazz = class.forname (parser);
//Make sure it extends Multipartrequest
if (!baseclazz.isassignablefrom (Clazz)) {
Adderror ("Class" + Parse R + "' does not extend Multipartrequest");
return;
}
//Get the constructor
constructor ctor = Clazz.getdeclaredconstructor (New class[]{
Class.forName ("Jav Ax.servlet.http.HttpServletRequest "),
Java.lang.String.class, Int.class
});
//Build the parameter list
object[] parms = new object[]{
Request, Savedir, new Integer (maxSize)
;
Instantiate it
Multi = (multipartrequest) ctor.newinstance (parms);
.................................................
}

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.