📄 upfileform.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -