有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java Jsf:使用IE9浏览器和所有其他工作方式,图像不上传到目的地

我使用了简单模式、netbean、glassfish 3.0和primefaces 3.0

扁豆

private UploadedFile file;
private String destination="D:\\temp\\";

public void upload(FleUploadEvent event) {
    System.out.println("upload");
    FacesMessage msg = new FacesMessage("Success! ", event.getFile().getFileName() + " is uploaded.");  
    FacesContext.getCurrentInstance().addMessage(null, msg);
    try  {
        copyFile(event.getFile().getFileName(), event.getFile().getInputstream());
    } catch (IOException e) {
        e.printStackTrace();
    }
}
System.out.println("uploaf finished"); 

public void copyFile(String fileName, InputStream in) {
    try {
        // write the inputStream to a FileOutputStream
        OutputStream out = new FileOutputStream(new File(destination + fileName));
        int read = 0;
        byte[] bytes = new byte[1024];
        while ((read = in.read(bytes)) != -1) {
             out.write(bytes, 0, read);
        }
        in.close();
        out.flush();
        out.close();
        System.out.println("New file created!");
    } catch (IOException e) {
        System.out.println(e.getMessage());
    }
}

这是我的jsf页面

<p:fileUpload fileUploadListener="#{fileUploadController.upload}" allowTypes="/(\.|\/)(gif|jpe?g|png)$/" sizeLimit="100000"/><br/>

共 (0) 个答案