如何向 t:inputfileupload 添加进度监听器?
到目前为止,我
在这里的尝试是 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();
}
}
so far my attempt
here is the jsp part
<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>
managed 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();
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用richfaces库。它的显示效果很好,并且有进度条。
use richfaces library. Its display is good and have a progress bar.