使用jspSmartUpload下载文件
2010-07-21 11:56
399 查看
<%
SmartUpload su = new SmartUpload();
su.initialize(pageContext);
su.setContentDisposition(null);// 禁止浏览器自动开打
try {
su.downloadFile("/upload/abc.rar");
} catch (Exception e) {
e.printStackTrace();
}
%>
这是大多数网站的通用代码,但我在使用中总数会报以下错误
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
root cause
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
即Servlet规范说明,不能既调用 response.getOutputStream(),又调用response.getWriter(),无论先调用哪一个,在调用第二个时候应会抛出 IllegalStateException,因为在jsp中,out变量是通过response.getWriter得到的,在程序中既用了response.getOutputStream,又用了out变量,故出现以上错误。
解决方案:
在程序中添加:
out.clear();
out = pageContext.pushBody();
就可以了;
SmartUpload su = new SmartUpload();
su.initialize(pageContext);
su.setContentDisposition(null);// 禁止浏览器自动开打
try {
su.downloadFile("/upload/abc.rar");
} catch (Exception e) {
e.printStackTrace();
}
%>
这是大多数网站的通用代码,但我在使用中总数会报以下错误
HTTP Status 500 -
type Exception reportmessage
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: java.lang.IllegalStateException: getOutputStream() has already been called for this response org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:522) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:410) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266) javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
root cause
java.lang.IllegalStateException: getOutputStream() has already been called for this response org.apache.catalina.connector.Response.getWriter(Response.java:610) org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:198) org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:125) org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:118) org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:186) org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:118) org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:77) org.apache.jsp.downfile_jsp._jspService(downfile_jsp.java:89) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:803) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:374) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266) javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.16 logs.
Apache Tomcat/6.0.16
经过研究这是web容器生成的servlet代码中有out.write(””),这个和JSP中调用的response.getOutputStream()产生冲突.即Servlet规范说明,不能既调用 response.getOutputStream(),又调用response.getWriter(),无论先调用哪一个,在调用第二个时候应会抛出 IllegalStateException,因为在jsp中,out变量是通过response.getWriter得到的,在程序中既用了response.getOutputStream,又用了out变量,故出现以上错误。
解决方案:
在程序中添加:
out.clear();
out = pageContext.pushBody();
就可以了;
相关文章推荐
- JSP中使用jspsmartupload组件进行文件的上传和下载
- 使用jspSmartUpload组件进行文件上传、下载、批量下载
- 使用jspSmartUpload的下载文件的经验教训
- 使用jspSmartUpload组件进行文件上传、下载
- jsp使用jspSmartUpLoad组件实现中文文件下载
- Java Web中使用JSPSmartUpload控件实现文件的上传和下载(解决了中文乱码问题)(JSP页面采用GBK编码)
- Java Web中使用JSPSmartUpload控件实现文件的上传和下载(解决了中文乱码问题)(JSP页面采用GBK编码)
- 项目开发技巧(四):使用JspSmartupload实现文件上传下载(一):JspSmart之upload组件源码及使用
- 使用jspSmartUpload组件进行文件上传、下载
- JSP 文件 下载 代码 (不使用 jsp smart upload 组件) 解决中文名 问题
- Servlet.service() for servlet jsp threw exception java.lang.Il在jsp中使用jspsmartupload组件下载文件时将抛出异常的解决方案
- 使用smartupload组件实现jsp+jdbc上传下载文件实例解析
- ExtJS中使用jspSmartUpload实现文件下载
- 使用jspSmartUpload组件进行文件上传、下载
- 项目开发技巧(四):使用JspSmartupload实现文件上传下载(二):jspSmartUpload上传下载全攻略(ZZ)
- 关于使用jspsmartupload.jar进行文件的上传与下载
- 项目开发技巧(四):使用JspSmartupload实现文件上传下载(三):jspsmartupload samples
- 使用jspSmartUpload组件进行文件上传、下载
- 使用smartupload组件实现jsp+jdbc上传下载文件
- 采用jspSmartUpload组件进行文件的下载