页面上传名称为 upload 提交表单方式为Post 类型为multipart/form-data ,
如下
method="post" enctype="multipart/form-data"
// 文件上传 upload 注意生成get/set方法
private File upload;
private String uploadContentType; // 文件的内容类型
private String uploadFileName; // 上传文件名
public String saveBatch()
{
try
{
ServletContext context = ServletActionContext.getServletContext();
// 文件上传目录
String targetDirectory = context.getRealPath("/upload");
String targetFileName = uploadFileName;
File target = new File(targetDirectory, targetFileName);
FileUtils.copyFile(upload, target);
// 保存文件的存放路径
setUploadFileName(target.getPath());
}
catch (Exception e)
{
message = "文件上传失败";
e.printStackTrace();
return ERROR;
}
return SUCCESS;
}