本地tomcat5.5没有此问题。一切正常
代码如下:
<%
byte[] bytes=......//文件流
String file_type = (String)file.getString("fileType");
response.setContentType(file_type);
//System.out.println("---" + file_type + "---" + bytes.length);
response.setHeader("Content-Disposition", "attachment;filename=\"" + new String(file.getString("fileName").getBytes("gb2312"), "ISO8859-1" ) + "\"");
response.setHeader("Pragma", "No-cache");
java.io.OutputStream output = response.getOutputStream();
try{
output.write(bytes);
output.flush();
response.flushBuffer();
out.clear();
out = pageContext.pushBody();
}catch(java.io.IOException e){
System.out.println("Error!");
e.printStackTrace();
} finally {
if (output != null) {
output.close();
output = null;
}
}
%>
报错如下:
java.io.IOException: response already committed
at weblogic.servlet.jsp.JspWriterImpl.clear(JspWriterImpl.java:56)
at jsp_servlet._mpcommon.__show_file._jspService(__show_file.java:111)
at weblogic.servlet.jsp.JspBase.service(JspBase.java:34)
at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283)
at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:42)
output.write(bytes);
output.flush();
response.flushBuffer();
out.clear();
out = pageContext.pushBody();
===>
output.write(bytes);
output.flush();
out = pageContext.pushBody(); 电加热炉温度控制系统的设计
response.flushBuffer();
out.clear();
如果你用weblogic 乱码问题就出现在这一句
response.setHeader("Content-Disposition", "attachment;filename=\"" + new String(file.getString("fileName").getBytes("gb2312"), "ISO8859-1" ) + "\""); 中的 new String(file.getString("fileName").getBytes("gb2312"), "ISO8859-1" ), 把new String(.getBytes("gb2312"),"ISO8859-1")去掉就行了。
用tomcat是正常的。