浏览 14737 次
锁定老帖子 主题:struts中多文件上传
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2005-12-19
试图在Action中,自己利用FileUpload得接口去处理上传的文件,发现在经过struts处理后,传入Action中的HttpServletRequest已经不在包含上传的文件。 不知大家有好办法吗? 从网上找到http://www.junlu.com/msg/164036.html,里面提到去修改struts中上传文件的处理类CommonsMultipartRequestHandler中的方法。 其中提到的方法,并没有测试提供支持,不知道大家有没有用过? 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2005-12-20
1.在form中定义
private FormFile[] referenceFormFile = new FormFile[10]; 2.页面里定义 <td><%for (int i = 0; i < 10; i++) { %> <html:file property='<%="referenceFormFile["+i+"]"%>' size="40"/><br> <% } %> 3.acton里 for (int i = 0; i <10; i++) { FormFile file = fileForm.getReference(i); String fileName = file.getFileName(); ......... ....... } |
|
返回顶楼 | |
发表时间:2005-12-20
不好意思,我刚接触这方面,请多指教。
|
|
返回顶楼 | |
发表时间:2005-12-23
我用过,很好。
|
|
返回顶楼 | |
发表时间:2005-12-26
这篇文章写的不错。很适合新手看。
http://java.chinaitlab.com/Spring/39277.html |
|
返回顶楼 | |
发表时间:2005-12-29
String dirPath = getServlet().getServletContext().getRealPath("/")
+ "/upload"; Hashtable fileh = actionForm.getMultipartRequestHandler(). getFileElements(); for (Enumeration e = fileh.keys(); e.hasMoreElements(); ) { String key = (String) e.nextElement(); try { FormFile formfile = (FormFile) fileh.get(key); String filename = formfile.getFileName().trim(); //文件名 if (!"".equals(filename)) { //不同的浏览器传上的文件名可能有区别,有的是全路径的 //在这里保存文件 InputStream ins = formfile.getInputStream(); OutputStream os = new FileOutputStream(dirPath + File.separatorChar + filename); int bytesRead = 0; byte[] buffer = new byte[8192]; while ((bytesRead = ins.read(buffer, 0, 8192)) != -1) { os.write(buffer, 0, bytesRead); } os.close(); ins.close(); } } catch (Exception ex) { logger.debug("出错了", ex); } } |
|
返回顶楼 | |