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; }
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。