jsp中輸出word文件的問題

cqyaoran發表於2005-11-19
我在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)

相關文章