这是我得到的错误:
java.io.FileNotFoundException: C:\Users\Owner\AppData\Roaming\NetBeans\7.3.1\config\GF3\domain1\generated\jsp\uploadRamki\data\images.jpg(系统找不到指定的路径)
这是我的支持 bean:
package beans;
import java.io.IOException;
import javax.inject.Named;
import javax.enterprise.context.SessionScoped;
import java.io.Serializable;
import javax.servlet.http.Part;
@Named(value = "demoBean")
@SessionScoped
public class DemoBean implements Serializable {
private Part file1;
public Part getFile1() {
return file1;
}
public void setFile1(Part file1) {
this.file1 = file1;
}
// getters and setters for file1 and file2
public String upload() throws IOException {
file1.write("c:/data/" + getFilename(file1));
return "success";
}
private static String getFilename(Part part) {
for (String cd : part.getHeader("content-disposition").split(";")) {
if (cd.trim().startsWith("filename")) {
String filename = cd.substring(cd.indexOf('=') + 1).trim()
.replace("\"", "");
return filename.substring(filename.lastIndexOf('/') + 1)
.substring(filename.lastIndexOf('\\') + 1); // MSIE fix.
}
}
return null;
}
}