ITeye博客

解析ZXINSPC程序

Riancy007 · 2007-11-30 16:18 · 技术田地 · Markdown

org.springframework.web.multipart.multiparthttpservletrequest类中就有个方法getfile(),将一

般的文件转换成multipartfile类型的文件,在用transferTo(“目标文件”)就可以实现上传了。 例如下面这段代码

MultipartHttpServletRequest mRequest = (MultipartHttpServletRequest) request; MultipartFile file = mRequest.getFile("inspPlanA");//"inspPlanA"是上传控件的ID f=new java.io.File(d:+"/"+test.txt); file.transferTo(f);

下载文件时: <%@ page contentType="application/x-msdownload"%> <%@ page import="java.net.URLEncoder"%> <% String str = request.getParameter("fileName"); String fileUrl=new String(str.getBytes("ISO8859-1"), "GBK"); String fileName=fileUrl.substring(fileUrl.lastIndexOf("/")+1); response.setContentType("bin"); response.addHeader("Content-Disposition","attachment;filename=""+URLEncoder.encode

(fileName,"UTF-8")+"""); response.setContentType("application/x-download"); try{ RequestDispatcher dispatcher = application.getRequestDispatcher(fileUrl); if(dispatcher != null){ dispatcher.forward(request,response); } response.flushBuffer(); out.clear(); out = pageContext.pushBody(); }catch(Exception e){ e.printStackTrace(); }finally{ } %>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。