日期:2014-05-17 浏览次数:20786 次
private File doc; private String docContentType; private String docFileName; private String path; public String execute() throws Exception{ docFileName=getFileName(docFileName); System.out.println(docFileName); FileOutputStream fos = new FileOutputStream(getPath()+"\\"+docFileName); //FileOutputStream fos = new FileOutputStream(ServletActionContext.getServletContext().getRealPath(getPath())+"\\"+docFileName); FileInputStream fis=new FileInputStream(doc); byte[] b=new byte[1024]; int length=0; while((length=fis.read(b))>0){ fos.write(b,0,length); } return SUCCESS; } public String getFileName(String fileName){ int position = fileName.lastIndexOf("."); String extension=fileName.substring(position); return System.currentTimeMillis()+extension; }
<action name="myUpload" class="action.MyUpload"> <param name="path">/upload</param> <result name="success">/fileupload/uploadSuccess.jsp</result> <result name="input">/fileupload/upload.jsp</result> </action>