我现在正在尝试使用 primefaces 而不是自制的文件上传系统,我遇到的唯一问题是它似乎什么也没做,有什么想法吗?
我正在使用 glassfish,我添加了
commons-io-1.4.jar commons-fileupload-1.2.1/jar
到我在 netbeans 中的图书馆
这是我的 xhtml
<p:fileUpload fileUploadListener="#{fileUploadController.upload}"
mode="advanced"
update="messages"
sizeLimit="100000000"
allowTypes="/(\.|\/)(gif|jpe?g|png)$/"/>
<p:growl id="messages" showDetail="true"/>
网页.xml,
<filter>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class>
<init-param>
<param-name>thresholdSize</param-name>
<param-value>51200</param-value>
</init-param>
<init-param>
<param-name>uploadDirectory</param-name>
<param-value>C:\Users\Richard\printing~subversion\fileupload\web\Uploaded</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>PrimeFaces FileUpload Filter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
文件上传控制器.java
@ManagedBean(name="fileUploadController")
public class FileUploadController {
private String destination="C:/Users/Richard/printing~subversion/fileupload/web/Uploaded";
public void upload(FileUploadEvent event) {
FacesMessage msg = new FacesMessage("Success! ", event.getFile().getFileName() + " is uploaded.");
FacesContext.getCurrentInstance().addMessage(null, msg);
// Do what you want with the file
try {
copyFile(event.getFile().getFileName(), event.getFile().getInputstream());
} catch (IOException e) {
e.printStackTrace();
}
}
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());
}
}
}
我也试过这个例子:http ://e-blog-java.blogspot.co.uk/2010/04/ppr-multi-file-upload-with-primefaces.html
但问题是当我复制代码时我无法上传显示?
有人知道发生了什么吗?
谢谢