STRUTS2 Security Plug-in struts2-secure-jakarta-multipart-parser-plugin caused by file upload problem

Source: Internet
Author: User

The framework of the new project is SSH, using the Struts2 file upload function, but found that the project after Eclipse startup, only the first time to upload the file is OK, the upload will be reported

2018- on- the  +: +: -[http-nio-8080-exec-7] Error:com.cs.lexiao.admin.basesystem.component.core.attachmentserviceimpl#save:source'/home/vobile/workspace_trph/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/work/catalina/localhost/ Lexiao-admin/upload_2df39ff2_d4c7_49ef_a521_925b0e85c43a_00000001.tmp'does not existjava.io.FileNotFoundException:Source'/home/vobile/workspace_trph/.metadata/.plugins/org.eclipse.wst.server.core/tmp1/work/catalina/localhost/ Lexiao-admin/upload_2df39ff2_d4c7_49ef_a521_925b0e85c43a_00000001.tmp'does not exist at Org.apache.commons.io.FileUtils.copyFile (Fileutils.java:1004) at Org.apache.commons.io.FileUtils.copyFile (Fileutils.java:968) at Com.cs.lexiao.admin.basesystem.component.core.AttachmentServiceImpl.save (Attachmentserviceimpl.java: 367) at Com.cs.lexiao.admin.basesystem.component.core.AttachmentServiceImpl.save (Attachmentserviceimpl.java: 217) at com.cs.lexiao.admin.basesystem.component.core.attachmentserviceimpl$ $FastClassByCGLIB $$99f22be.invoke ( <generated>) at Net.sf.cglib.proxy.MethodProxy.invoke (Methodproxy.java:204) at Org.springframework.aop.framework.cglib2aopproxy$cglibmethodinvocation.invokejoinpoint ( Cglib2aopproxy.java:689) at Org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (Reflectivemethodinvocation.java:  Max) at Org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor.invoke (Throwsadviceinterceptor.java: 124) at Org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (Reflectivemethodinvocation.java: 172) at Org.springframework.transaction.interceptor.TransactionInterceptor.invoke (Transactioninterceptor.java:  the) at Org.springframework.aop.framework.ReflectiveMethodInvocation.proceed (Reflectivemethodinvocation.java: 172) at Org.springframework.aop.framework.adapter.ThrowsAdviceInterceptor.invoke (Throwsadviceinterceptor.java: 124)

Because struts will put the file under the/TMP1, generated a xxxx.tmp temporary file, and reported that this error is not found in this temporary file, tracking the next struts2 Fileuploadinterceptor,

Enumeration Fileparameternames =Multiwrapper.getfileparameternames ();  while(Fileparameternames! =NULL&&fileparameternames.hasmoreelements ()) {            //get the value of this input tagString InputName =(String) fileparameternames.nextelement (); //get the content typestring[] ContentType =multiwrapper.getcontenttypes (InputName); if(Isnonempty (ContentType)) {//Get the name of the file from the input tagstring[] FileName =multiwrapper.getfilenames (InputName); if(Isnonempty (fileName)) {//get a File object for the uploaded filefile[] Files =multiwrapper.getfiles (InputName); if(Files! =NULL&& files.length > 0) {List<File> Acceptedfiles =NewArraylist<file>(files.length); List<String> acceptedcontenttypes =NewArraylist<string>(files.length); List<String> Acceptedfilenames =NewArraylist<string>(files.length); String ContentTypeName= InputName + "ContentType"; String Filenamename= InputName + "FileName";  for(intindex = 0; Index < files.length; index++) {                            if(Acceptfile (Action, Files[index], Filename[index], Contenttype[index], inputname, validation)) {                                Acceptedfiles.add (Files[index]);                                Acceptedcontenttypes.add (Contenttype[index]);                            Acceptedfilenames.add (Filename[index]); }                        }                        if(!Acceptedfiles.isempty ()) {Map<string, object> params =ac.getparameters (); Params.put (InputName, Acceptedfiles.toarray (Newfile[acceptedfiles.size ()]); Params.put (ContentTypeName, Acceptedcontenttypes.toarray (Newstring[acceptedcontenttypes.size ()]); Params.put (Filenamename, Acceptedfilenames.toarray (Newstring[acceptedfilenames.size ()]); }                    }                } Else {                    if(log.iswarnenabled ()) {Log.warn (Gettextmessage (action),"Struts.messages.invalid.file",Newstring[]{inputname})); }                }            } Else {                if(log.iswarnenabled ()) {Log.warn (Gettextmessage (action),"Struts.messages.invalid.content.type",Newstring[]{inputname})); }            }

Found that Acceptedfiles has multiple files, exactly how many have been uploaded before, and I actually only upload a file, and the temporary directory only I upload this file, corresponding to the Java code will only accept a file, the default takes the first _ 00000001.tmp, and the actual existence is _00000004.tmp, then the error.

Why is it? At that time the suspicion is the front-end problem, but did not find the reason. Later I used the postman to upload files to the back end, found that the problem is still, the problem is back-end. The last is to comment out a previously added struts2 security plug-in

Struts.xml

<type= "Org.apache.struts2.dispatcher.multipart.MultiPartRequest"            Class= "Org.apache.struts.extras.SecureJakartaMultipartParser"           name= " Secure-jakarta "           scope=" prototype "/>         <   name= "Struts.multipart.parser"  value= "Secure-jakarta"/ >     

It would be nice to struts.xml the paragraph in the note.

What is the final reason? Have not begun to analyze the plug-in, to be continued.

STRUTS2 Security Plug-in struts2-secure-jakarta-multipart-parser-plugin caused by file upload problem

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.