How to run external class files in a Java program

Source: Internet
Author: User
After you click the upload button Program The stream is as follows:
Step 1) Enter servletdispatcher. Service
Public void Service (httpservletrequest request, httpservletresponse response) throws servletexception {
........

Request = wraprequest (request );
.........
}

Step 2) Enter servletdispatcher. wraprequest
Protected httpservletrequest wraprequest (httpservletrequest request) throws ioexception {
........................

If (multipartrequest. ismultipart (request )){
Request = new multipartrequestwrapper (request, getsavedir (), getmaxsize ());
}

Return request;
}

Step 3) enter the multipartrequestwrapper Constructor
Public multipartrequestwrapper (httpservletrequest request, string savedir, int maxsize) throws ioexception {
.....................
// Step3.1) obtain the parser configured by webwork. preperties.
String parser = "";

Parser = configuration. getstring ("webwork. multipart. parser ");

// If it's not 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. opensymphony. 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) Get and instantiate parser through reflection
Try {
Class baseclazz = com. opensymphony. webwork. Dispatcher. multipart. multipartrequest. Class;

Class clazz = Class. forname (parser );

// Make sure it extends multipartrequest
If (! Baseclazz. isassignablefrom (clazz )){
Adderror ("class" + parser + "'does not extend multipartrequest ");

Return;
}

// Get the constructor
Constructor ctor = clazz. getdeclaredconstructor (new class [] {
Class. forname ("javax. 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 );
........................................ .........
}

// Step 4: Enter the construction method of jakartamultipartrequest
Public jakartamultipartrequest (httpservletrequest servletrequest, string savedir, int maxsize)
Throws ioexception {

// Set save Parameters
Diskfileupload upload = new diskfileupload ();
// We must store all uploads on disk because the WW multipart API is missing streaming
// Capabilities
Upload. setsizethreshold (0 );
Upload. setsizemax (maxsize );
If (savedir! = NULL ){
Upload. setrepositorypath (savedir );
}

// Parse the request
Try {

// Generate a file by using this method. A temporary file such as upload_00000017.tmp and upload_00000018.tmp is generated for each parameter in the request, even for parameters submitted by form.
List items = upload. parserequest (servletrequest );

......................
}
After completing step 4, we will launch servletdispatcher. wraprequest To Go To The serviceaction method and start the stack call of the action and its interceptor.

In this process, temporary files that are not uploaded will be deleted. As for which step to delete the files, I haven't seen it yet. Sometimes it is very late and sometimes it is not even deleted, I suspect a dameon is doing this.

After entering the action and call stack, the interceptor or action can use the followingCodeAccess the uploaded temporary file
Multipartrequestwrapper wrapper = (multipartrequestwrapper) req;
File Doc = wrapper. getfiles ("Doc") [0];

From the above analysis, we can see that:
1) if you use webwork to upload files (do not modify the source code before entering the action stack or perform some extensions, overwrites, and other actions), the files are uploaded when you enter the action stack, and its file name is difficult to track (upload_00000017.tmp, Which is 00000017,0000018, or 0000022). After all, many people upload files, so it is difficult to determine the temporary file name, therefore, it is difficult to know the upload progress.
2) using webwork to upload files is a two-copy process. webwork first outputs the file stream from the request input stream to a temporary file, then copy the temporary file to the path you need to specify. Is this good or bad? 

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.