为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

Weblogic下载错误-called with unsafe path & 用jspsmartupload下载文件

2017-10-22 8页 doc 23KB 24阅读

用户头像

is_260251

暂无简介

举报
Weblogic下载错误-called with unsafe path & 用jspsmartupload下载文件Weblogic下载错误-called with unsafe path & 用jspsmartupload下载文件 用jspsmartupload下载文件 一般无论网站还是其他系统都会用到文件的上传和下载,对于文件 的上传前面已经介绍过了,在本文中将详细介绍一下文件的下载实现以 及经常碰到的问题,本文代码已经过调试,可以正常使用: 文件的下载一般采用的有两种方式:通过流或利用jspsmartupload.jar下载。 一.采用数据流下载: 第一个页面:(存在“下载”按钮的页面) function doDownlo...
Weblogic下载错误-called with unsafe path & 用jspsmartupload下载文件
Weblogic下载错误-called with unsafe path & 用jspsmartupload下载文件 用jspsmartupload下载文件 一般无论网站还是其他系统都会用到文件的上传和下载,对于文件 的上传前面已经介绍过了,在本文中将详细介绍一下文件的下载实现以 及经常碰到的问题,本文代码已经过调试,可以正常使用: 文件的下载一般采用的有两种方式:通过流或利用jspsmartupload.jar下载。 一.采用数据流下载: 第一个页面:(存在“下载”按钮的页面) function doDownload(filePath,disName) { var utl="download.jsp?filePath="+filePath+"&disName="+disName; document.all.opForm.action=url; // document.all.opForm.target="_blank"; document.all.opForm.submit(); }
’,’<%=fileName%>’)” value=”下载”>
第二个页面(download.jsp): <%@ page import="java.io.OutputStream" %> <%@ page import="java.io.FileInputStream" %> <% //response.reset(); //filePath为全路径:D:/upload/a.doc String path = request.getParameter("filePath"); int k = path.lastIndexOf("/"); String name = path.substring(k + 1 , path.length()); response.setContentType("unknown"); response.addHeader("Content-Disposition","filename=\"" + name + "\""); try { OutputStream os = response.getOutputStream(); FileInputStream fis = new FileInputStream(path); byte[] b = new byte[1024]; int i = 0; while((i = fis.read(b)) > 0) { os.write(b, 0 ,i); } fis.close(); os.flush(); os.close(); } catch(Exception e) { e.printStackTrace(); } %> 如果只是这样写在tomcat底下可以正常使用,但weblogic底 下会报如下错误: java.net.ProtocolException: Exceeded stated content-length of: '19456' bytes at weblogic.servlet.internal.ServletOutputStreamImpl.checkCL(ServletOutput StreamImpl.java:219) at weblogic.servlet.internal.ServletOutputStreamImpl.write(ServletOutputStre amImpl.java:170) at com.jspsmart.upload.SmartUpload.downloadFile(SmartUpload.java:579) at com.jspsmart.upload.SmartUpload.downloadFile(SmartUpload.java:508) at jsp_servlet._page.__download._jspService(__download.java:184) at weblogic.servlet.jsp.JspBase.service(JspBase.java:33) at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:1053) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:387) at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:431) at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:28) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27) at com.nstc.web.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:30) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:27) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6297) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:97) at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3575) at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2573) at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:178) at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:151) > 这是因为weblogic会向response中写东西造成的,解决方式是将此句 response.reset();的注释打开,这样在使用response时先将其重置。 二 .利用jspsmartupload.jar实现下载 第一个页面同上 download.jsp实现如下: <%@ page contentType="text/html;charset=gb2312"%> <%@ page import="com.jspsmart.upload.*" %> <%! public String toUtf8String(String s) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < s.length(); i++) { char c = s.charAt(i); if (c >= 0 && c <= 255) { sb.append(c); } else { byte[] b; try { b = Character.toString(c).getBytes("utf-8"); } catch (Exception ex) { System.out.println(ex); b = new byte[0]; } for (int j = 0; j < b.length; j++) { int k = b[j]; if (k < 0) k += 256; sb.append("%" + Integer.toHexString(k).toUpperCase()); } } } return sb.toString(); } %> <% response.reset();//如果在weblogic底下同样要加上此句 String filePath = request.getParameter("filePath"); String disName = request.getParameter("disName"); // 新建一个SmartUpload对象 SmartUpload su = new SmartUpload(); // 初始化 su.initialize(pageContext); ntentDisposition为null以禁止浏览器自动打开文件, // 设定co //保证点击链接后是下载文件。若不设定,则下载的文件扩展名为 //doc时,浏览器将自动用打开它。扩展名为pdf时, //浏览器将用acrobat打开。 su.setContentDisposition(null); // 下载文件 String fileName = toUtf8String(disName); try{ su.downloadFile(filePath,null,fileName); } catch(java.io.FileNotFoundException e){ %> <%} %>下载完毕~ 至此文件下载介绍完毕。
/
本文档为【Weblogic下载错误-called with unsafe path &amp; 用jspsmartupload下载文件】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索