日期:2014-05-16  浏览次数:20330 次

jspsmartupload 下载文件出错提示:getOutputStream() has already been called

ype Exception report

message

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:528)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:417)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
 

root cause

java.lang.IllegalStateException: getOutputStream() has already been called for this response
org.apache.catalina.connector.Response.getWriter(Response.java:608)
org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:200)
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:189)
org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:122)
org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:79)
org.apache.jsp.do_005fdownload_jsp._jspService(do_005fdownload_jsp.java:74)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:68)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:376)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
 

note The full stack trace of the root cause is available in the Apache Tomcat/7.0.2 logs.

----------------------

?由于jsp container在处理完成请求后会调用releasePageContet方法释放所用的PageContext object,并且同时调用getWriter方法,由于getWriter方法与在jsp页面中使用流相关的getOutputStream方法冲突,所以会造成这种异常,解决办法是:

只需要在jsp页面的最后加上两条语句:??
out.clear();?
out=pageContext.pushBody();即可(其中out,pageContext均为jsp内置对象!)

?

 1<%@ page language="java" contentType="text/html; charset=utf-8"
 2    pageEncoding="utf-8" import="com.jspsmart.upload.*"%>
 3<%
 4    String dfilename = request.getParameter("dfilename");
 5
 6    SmartUpload su = new SmartUpload();
 7    su.initialize(pageContext);
 8    su.setContentDisposition(null);
 9    su.downloadFile("/upload/" + dfilename);
10    out.clear();
11    out = pageContext.pushBody();
12%>

?

?

?

?

?

注明:转自http://www.cppblog.com/fenglin/articles/126788.html


我的异常网推荐解决方案:The server encountered an internal error () that prevented it from fulfilling this request.,http://www.aiyiweb.com/java-web/317.html