到目前为止我尝试
这是jsp部分
<h:form id="fileUploader" enctype="multipart/form-data" target="upload_target" >
<h:panelGrid columns="4" width="100%">
<t:inputFileUpload id="file" value="#{FIleuploadservlet.uploadedFile}" required="true" />
<h:commandButton value="Submit" actionListener="#{FIleuploadservlet.uploadDirect}" onclick="setFormAction();" />
</h:panelGrid>
托管bean。。。
public void uploadDirect(ActionEvent ae)
{
HttpServletRequest request=(HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest();
HttpSession session=request.getSession();
try
{
byte[] data = new byte[(int) uploadedFile.getSize()];
uploadedFile.getInputStream().read(data, 0, (int) uploadedFile.getSize());
System.out.println("savefile===="+uploadedFile.getName());
File file=new File("c:\file");
if(!file.exists())
{
file.mkdirs();
}
FileOutputStream fileOut = new FileOutputStream("c:\file\lantern.avi");
fileOut.write(data, 0, data.length);
fileOut.flush();
fileOut.close();
}catch(Exception e)
{
e.printStackTrace();
}
}
使用richfaces库。它的显示很好,并且有一个进度条。