1: 在JSP中:
2:在Struts中:
/admin/upload.jsp /error.jsp /UploadFile.jsp 20000000000000 在外添加 nstant name="struts.multipart.maxSize"value="1000000000">constant3:在com.dota.action.UploadFileAction中: public String execute(){ String newFileName = ServletActionContext.getServletContext().getRealPath("/cs")+"/"+fileFileName; try { /*原理就是在本機內讀,在服務器上寫入在設置好的路徑內*/ InputStream is = new BufferedInputStream(new FileInputStream(file)); OutputStream os = new BufferedOutputStream(new FileOutputStream(newFileName)); byte[] buff = new byte[1000]; int i = 0; while( (i=is.read(buff))>0 ){ os.write(buff, 0, i); } is.close(); os.close(); } catch (Exception e) { e.printStackTrace(); return ERROR; } if(fileFileName!=null){ this.setFf("上傳成功,點擊查看:"); }else{ this.setFf("上傳失敗"); } return SUCCESS; }
本站僅提供存儲服務,所有內容均由用戶發(fā)布,如發(fā)現有害或侵權內容,請
點擊舉報。