用jspsmart下載文件異常(tomcat正常,weblogic不行)
用jspsmart下載文件JSP代碼如下:
<%@ page contentType="text/html;charset=GBK" import="com.jspsmart.upload.*" %><%
//取得服務器存放文件的路徑
String reportTemplatePath = (String)session.getAttribute("reportTemplatePath");
//文件名
String filename = reportTemplatePath + "/" + request.getParameter("filename");
filename = new String(filename.getBytes(),"ISO-8859-1");
// 新建一個SmartUpload對象
SmartUpload su = new SmartUpload();
// 初始化
su.initialize(pageContext);
//設定contentDisposition為null以禁止瀏覽器自動打開文件,保證點擊鏈接后是下載文件。若不設定,則下載的文件擴展名為
//doc時,瀏覽器將自動用word打開它。擴展名為pdf時,瀏覽器將用acrobat打開。
su.setContentDisposition(null);
// 下載文件
su.downloadFile(filename);
%>在tomcat中運行正常。
在weblogic中運行拋出如下異常.
文件可以下載,但特別慢并且打開是亂碼。
<2004-2-19 下午09時14分34秒> <Error> <HTTP> <101019> <[ServletContext(id=325867,
name=csrc,context-path=/csrc)] Servlet failed with IOException
java.net.ProtocolException: Exceeded stated content-length of: '548352' bytes
at weblogic.servlet.internal.ServletOutputStreamImpl.checkCL(ServletOutp
utStreamImpl.java:220)
at weblogic.servlet.internal.ServletOutputStreamImpl.write(ServletOutput
StreamImpl.java:170)
at com.jspsmart.upload.SmartUpload.downloadFile(SmartUpload.java:986)
at com.jspsmart.upload.SmartUpload.downloadFile(SmartUpload.java:355)
at com.jspsmart.upload.SmartUpload.downloadFile(SmartUpload.java:336)
at jsp_servlet._test.__do_download._jspService(__do_download.java:102)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
(ServletStubImpl.java:1058)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:401)
at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
pl.java:306)
at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
n.run(WebAppServletContext.java:5445)
at weblogic.security.service.SecurityServiceManager.runAs(SecurityServic
eManager.java:780)
at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
rvletContext.java:3105)
at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
pl.java:2588)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:213)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:189)
>
解決方法:把所有<%和%>之外的空格字符都取掉就好了.參考如下:
<%@ page contentType="text/html;charset=GBK" import="com.jspsmart.upload.*" %><%
//取得服務器存放文件的路徑
String reportTemplatePath = (String)session.getAttribute("reportTemplatePath");
//文件名
String filename = reportTemplatePath + "/" + request.getParameter("filename");
filename = new String(filename.getBytes(),"ISO-8859-1");
// 新建一個SmartUpload對象
SmartUpload su = new SmartUpload();
// 初始化
su.initialize(pageContext);
//設定contentDisposition為null以禁止瀏覽器自動打開文件,保證點擊鏈接后是下載文件。若不設定,則下載的文件擴展名為
//doc時,瀏覽器將自動用word打開它。擴展名為pdf時,瀏覽器將用acrobat打開。
su.setContentDisposition(null);
// 下載文件
su.downloadFile(filename);
%>