1 16 package dlog4j.formbean; 17 18 import javax.servlet.http.HttpServletRequest ; 19 import java.util.*; 20 21 import org.apache.struts.action.ActionError; 22 import org.apache.struts.action.ActionErrors; 23 import org.apache.struts.action.ActionMapping; 24 import org.apache.struts.upload.FormFile; 25 26 31 public class UploadForm extends DlogActionForm { 32 33 FormFile uploadFile = null; 34 String form = "forms[0]"; 35 38 public FormFile getUploadFile() { 39 return uploadFile; 40 } 41 42 45 public void setUploadFile(FormFile file) { 46 uploadFile = file; 47 } 48 49 52 53 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { 54 ActionErrors errors = new ActionErrors(); 55 if(uploadFile!=null){ 56 if(uploadFile.getFileSize()>1000000) 57 errors.add("uploadFile",new ActionError("upload_file_size_exceed")); 58 String fn = uploadFile.getFileName(); 59 int i=0; 60 for(;i<types.size();i++){ 61 if(fn.endsWith((String )types.get(i))) 62 break; 63 } 64 if(i==types.size()){ 65 errors.add("uploadFile",new ActionError("upload_file_extend_noallow")); 66 } 67 } 68 return errors; 69 } 70 public final static List types = Arrays.asList(new String []{"gif","jpg","bmp","png","swf"}); 71 74 public String getForm() { 75 return form; 76 } 77 78 81 public void setForm(String string) { 82 form = string; 83 } 84 85 } 86 | Popular Tags |