struts2 代码
public String upload() throws Exception {
String realpath = ServletActionContext.getServletContext().getRealPath("/upload") ;
if (image != null){
File savedir = new File(realpath) ;
if (! savedir.exists()) {
savedir.mkdirs() ;
}
File savefile = new File(realpath, imageFileName) ;
FileUtils.copyFile(image, savefile) ;
System.out.println(imageContentType);
}
ActionContext.getContext().put("message", "上传成功:" + realpath) ;
return "success" ;
}
HTML 代码
注意这点的 iframe
模拟iframe 可做到无刷新 提交
<iframe name="ajaxUpload" style="display:none"></iframe>
<form id ="foimage" method="POST" enctype="multipart/form-data" action="../upload.action" target="ajaxUpload">