upfileform.java

来自「实现一个J2EE上传功能完整的源代码」· Java 代码 · 共 101 行

JAVA
101
字号
package com.actionForm;import javax.servlet.http.HttpServletRequest;import org.apache.struts.action.ActionErrors;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionMapping;import org.apache.struts.action.ActionMessage;import org.apache.struts.upload.FormFile;public class UpFileForm extends ActionForm {	private String finfo;	private FormFile upfile;	private int fid;	private String fname;	private String ftype;	private int fsize;	private int default_size = 1024 * 1024 * 2;	public String getFinfo() {		return finfo;	}	public void setFinfo(String finfo) {		this.finfo = finfo;	}	public FormFile getUpfile() {		return upfile;	}	public void setUpfile(FormFile upfile) {		this.upfile = upfile;	}	public int getFid() {		return fid;	}	public void setFid(int fid) {		this.fid = fid;	}	public String getFname() {		return fname;	}	public void setFname(String fname) {		this.fname = fname;	}	public String getFtype() {		return ftype;	}	public void setFtype(String ftype) {		this.ftype = ftype;	}	public int getFsize() {		return fsize;	}	public void setFsize(int fsize) {		this.fsize = fsize;	}	public ActionErrors validate(ActionMapping mapping,			HttpServletRequest request) {		fname = upfile.getFileName();		fsize = upfile.getFileSize();		ftype = upfile.getContentType();		boolean mark = true;		ActionErrors errors = new ActionErrors();		if (fname == null || fname.equals("")) {			mark = false;			errors.add("fileM", new ActionMessage("file.up.nofile.e"));		}		if (mark) {			int pos = fname.lastIndexOf(".");			int name_1 = fname.length();			if (pos < 0 || pos == name_1 - 1) {				mark = false;				errors.add("fileM", new ActionMessage("file.up.filename.e",						fname));			}		}		if (mark) {			if (fsize > default_size) {				mark = false;				errors.add("fileM",						new ActionMessage("file.up.filesize.e", "2"));			}		}		return errors;	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?