浏览 2133 次
锁定老帖子 主题:利用webwork进行上传
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2007-07-17
package com.Jskyben.test; /*author:skyact 多文件上传功能 */ import com.opensymphony.xwork.ActionSupport; import java.io.*; import javax.servlet.ServletContext; import com.opensymphony.xwork.ValidationAware; import javax.servlet.http.HttpServletRequest; import com.opensymphony.webwork.dispatcher.multipart.*; import com.opensymphony.webwork.ServletActionContext; import com.opensymphony.webwork.interceptor.ServletRequestAware; public class UploadDoc1 extends ActionSupport implements ValidationAware,ServletRequestAware{ private File[] doc; private String[] docContentType; private String[] docFileName; private String message=""; ServletContext d; HttpServletRequest req; public String execute() throws Exception{ MultiPartRequestWrapper wrapper=(MultiPartRequestWrapper)req; message=wrapper.getParameter("message");//取得表单中其他字段值 d=ServletActionContext.getServletContext(); String path=d.getRealPath("/");//取得根目录 path+="pic/"; for(int i=0;i<doc.length;i++){//多文件上传 File target = new File(path+docFileName[i]); if(target.exists()){ target.delete(); } doc[i].renameTo(target); } return SUCCESS; } public void setServletRequest(HttpServletRequest req){ this.req=req; } public void validate(){ if(doc==null||doc.equals("")){ addFieldError("doc", getText("file not found,please upload a file"));} } public void setDoc(File[] doc) { this.doc = doc; } public void setDocContentType(String[] docContentType) { this.docContentType = docContentType; } public void setDocFileName(String[] docFileName) { this.docFileName = docFileName; } public String getMessage(){ return message; } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |