struts2中的s:file标签怎么限定上传文件为图片类型,最好是能在选择文件时就只能选择图片文件

struts2中的s:file标签怎么限定上传文件为图片类型,最好是能在选择文件时就只能选择图片文件






text/plain,text/css,text/javascript

冲橘1000000


/散激团uploads
/success.jsp
/failure.jsp
/failure.jsp




package g2w.struts2;

import java.io.File;
import java.io.IOException;

import org.apache.commons.io.FileUtils;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.ActionSupport;

public class FileUploadAction extends ActionSupport {
private static final long serialVersionUID = 1L;

private File file;
private String fileContentType;
private String fileFileName;

private String savePath;

// setters & getters

public String execute() {
try {
File destFile = new File(this.getSavePath(), fileFileName);
FileUtils.copyFile(this.file, destFile);
// ....
} catch (IOException e) {
this.setMessage(e.getMessage());
return ActionSupport.ERROR;
}
return SUCCESS;
}
}
← 上一篇: 下一篇: →