An error has occurred in this application. java. lang. runtimeexception: Unable to load bean Org. apache. struts2.dispatcher. multipart. multipartrequest (Jakarta)-[unknown location] at com. opensymphony. xwork2.inject. containerbuilder $4. create (containerbuilder. java: 136)
At COM. opensymphony. xwork2.inject. containerimpl. getinstance (containerimpl. java: 476) at com. opensymphony. xwork2.inject. containerimpl. getinstance (containerimpl. java: 486) at com. opensymphony. xwork2.inject. containerimpl $9. call (containerimpl. java: 517) at com. opensymphony. xwork2.inject. containerimpl. callincontext (containerimpl. java: 542)
At ........
For many people on the Internet, it is because there is no jar package: such as commons-io.jar and commons-fileupload.jar, this situation is easy to solve
But I was added or reported error, found through Google for a long time to know that the two jar packages are Version 1.1, or commons-io.jar and commons-fileupload.jar default, the original in struts2 upload
The file will cause a conflict, and then I changed to commons-io-1.4.jar and commons-fileupload-1.32.jar just fine.
After upgrading the jar package, you do not need to configure a filter named actioncontextup in the web. xml file,
Let's talk about the upload Implementation of struts2:
Private file;
// File type (1. Automatic System injection 2. variable naming rules foreground object name + "contenttype ")
Private string filecontenttype;
// Name of the uploaded file (1. the system automatically injects the file. 2. The variable naming rules are as follows: foreground object name + "FILENAME ")
Private string filefilename;
Private string savepath;
In addition to the file and savepath attributes (which can be dynamically injected through configuration), this action has two attributes:Uploadfilename and uploadcontenttypeThese two attributes are respectively used to encapsulate the file name and file type of the uploaded file. This is unique in struts2 design: The action class of strut2 directly encapsulates the file content of the uploaded file through the file type attribute, but this file attribute cannot obtain the file name and file type of the uploaded file, therefore, struts2 directly encapsulates the uploaded file name and file type information in the file field into the uploadfilename and uploadcontenttype attributes, that is, struts2 targets the file field named XXX in the form, use three attributes in the corresponding action class to encapsulate the file domain information:
The xxx attribute of Type L is file: Used to encapsulate the file content corresponding to the page file domain.
The xxxfilename attribute of string type: Used to encapsulate the file name corresponding to the file field.
The xxxcontenttype attribute of string type: the file type used to encapsulate the files in the file domain.
In addition, there is a savepath attribute in this action class, whose values are dynamically set through the configuration file, which is also used as a dependency injection feature in the strut2 design.
Take the image as an example:
There are three core codes. The others are all written around these three core codes, and the corresponding geter and seter
Java code
1. // 1. Obtain the path to write the image
2. String realpath = servletactioncontext. getservletcontext (). getrealpath ("/images"); // The actual path
// 1. Get the path to write the image
String realpath = servletactioncontext. getservletcontext (). getrealpath ("/images"); // actual path
Java code
1. // 2. Create a file under this path
2. File SaveFile = new file (realpath), filetestfilename); // instantiate a file in the actual path
// 2. Create a file in this path
File SaveFile = new file (realpath), filetestfilename); // instantiate a file in the actual path
Java code
1. // 3. Copy the uploaded file to the above instantiated file, which may throw an exception and need to be captured
2. fileutils. copyfile (filetest, SaveFile );
For details, refer:
Http://tmsoft.lsxy.com/index.php? Load = read & id = 514