If the file upload is unsuccessful, the default is return "input" <result name= "Success" >/success.jsp</result> <result name= "Input" >/ Index.jsp</result>Single File upload servletcontext context=Servletactioncontext.getservletcontext (); just get Webroot String dir=context.getrealpath ("/files/" +pptfilename); System.out.println (dir); FileOutputStream Fos=NewFileOutputStream (dir); FileInputStream FIS=NewFileInputStream (PPT); byte[] buffer=New byte[1024]; intLen=0; while(Len=fis.read (buffer))!=-1) {fos.write (buffer,0, Len); } fos.close (); Fis.close (); upload limit<interceptors> <interceptor-stack name= "Fileup" > <interceptor-ref name= "defaultstack" > <para M name= "fileupload.maximumsize" >2000</param> <param name= "Fileupload.allowedtypes" >text/plain,text /plain</param> <param name= "fileupload.allowedextensions" >html,dtd,xml</param> </ Interceptor-ref> </interceptor-stack> </interceptors>Image/png,image/bmp,image/jpg<default-interceptor-ref name= "Fileup" ></default-interceptor-ref><s:form action= "S/upload_upload" method= "POST"enctype= "Multipart/form-data" theme= "simple" > <s:fielderror name= "ppt" ></s:fielderror>File:<s:file name= "ppt" label= "file" ></s:file>Pptdesca:<s:textfield name= "pptdesc[0" "label=" Pptdesca "></s:textfield> while(Iterator.hasnext ()) {File File=(File) iterator.next (); String dir=context.getrealpath ("/resource/image/knowledge/upload/" +Caseimgfilename.get (caseimg.)); System.out.println (dir+ "***********dir"); Try{FIS=Newfileinputstream (file); FOS=NewFileOutputStream (dir); byte[] bs=New byte[1024]; intLen=0; while((Len=fis.read (BS))!=-1) {fos.write (BS,0, Len); } } Catch(FileNotFoundException e) {//TODO auto-generated Catch blockSYSTEM.OUT.PRINTLN ("File input Error"); } Catch(IOException e) {//TODO auto-generated Catch blockE.printstacktrace (); }finally{ Try{fos.close (); Fis.close (); } Catch(IOException e) {//TODO auto-generated Catch blockSYSTEM.OUT.PRINTLN ("input stream, output stream shutdown error"); } } }
String rpath= "resource/image/knowledge/upload/"; the path stored in the database cannot be an absolute path must be a relative path
Struts File Upload