package com.jzaccp.web;import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;import org.apache.commons.io.CopyUtils;
import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionSupport;public class Save extends ActionSupport {
private File file; public File getFile() {
return file;
} public void setFile(File file) {
this.file = file;
} public String execute() throws Exception {
if (file!=null) {
String path=ServletActionContext.getServletContext().getRealPath("/image");
FileInputStream inputStream=new FileInputStream(file);
File save=new File(path,file.getName()); FileOutputStream outputStream=new FileOutputStream(save);
CopyUtils.copy(inputStream, outputStream);
inputStream.close();
outputStream.close();
//为什么我得到的文件总是.tmp的后缀 }
return SUCCESS;
}
}我的网页
<form action="upload.do" method="post" enctype="multipart/form-data" >
    <label>
      <input type="file" name="file" id="fileField">
       <input type="text" name="fileName" id="fileField">
    </label>
    <label>
      <input type="submit" name="button" id="button" value="提交">
    </label>
  </form>