jsp中输出word文档的问题

05-11-19 cqyaoran
我在jsp页面输出word文档为什么报错?

<%@ page contentType="application/msword; charset=gb2312" language="java" errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="application/msword; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<%
response.reset();
response.setContentType("application/msword");
response.setHeader("Content-disposition","inline; filename=temp.doc");
byte[] word=(byte[])request.getAttribute("scanlist");
javax.servlet.ServletOutputStream os = response.getOutputStream();
os.write(word);
os.close();
%>
</body>
</html>


错误显示为:
10:48:01,703 ERROR StandardWrapper[/ygt:jsp]:727 - Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response
at org.apache.catalina.connector.Response.getWriter(Response.java:595)
at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:161)
at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:123)
at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:116)
at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:190)
at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:115)
at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
at org.apache.jsp.customer.show_005fword_005fdoc_jsp._jspService(org.apache.jsp.customer.show_005fword_005fdoc_jsp:61)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:99)

猜你喜欢