servlet getWriter() has already been called for this response

Servlet代码:
OutputStream os = response.getOutputStream();
response.setContentType("application/msexcel");
response.setHeader("Content-disposition","attachment;   filename=Excel1.xls");
报错:getWriter() has already been called for this response
解决办法:
response.reset();加入这句就搞定了
OutputStream os = response.getOutputStream();
response.setContentType("application/msexcel");
response.setHeader("Content-disposition","attachment;   filename=Excel1.xls");

你可能感兴趣的:(servlet,文件输出流)