java 文件下载时报错,具体代码如下,麻烦大侠给帮忙看看, 100
HttpServletResponseres=super.response();Stringpath=downloadFileMap.get("downPath");re...
HttpServletResponse res = super.response();
String path = downloadFileMap.get("downPath");
res.setContentType("application/OCTET-STREAM");
OutputStream outStrem = null;
BufferedInputStream inputStream = null;
try
{
res.setHeader("Content-disposition", "attachment;filename="
+ fileName.replace(" ", "%20"));
outStrem = res.getOutputStream();
inputStream = new BufferedInputStream(new FileInputStream(path));
StreamUtils.copy(inputStream, outStrem);
inputStream.close();
outStrem.close();
}
catch (IOException e)
{
e.printStackTrace();
}
报错如下:
java.lang.IllegalStateException: STREAM
at org.eclipse.jetty.server.Response.getWriter(Response.java:920)
at com.inspur.common.http.dispatcher.ActionHelper.writeOperResult(ActionHelper.java:105)
at com.inspur.common.http.dispatcher.WebDispatcher.doPost(WebDispatcher.java:124)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:800)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1125)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1059)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:497)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:248)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:620)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:540)
at java.lang.Thread.run(Thread.java:745)
2015-06-24 10:39:43.960:WARN:oejs.HttpChannel:qtp22348929-102: /ajax.do?action=core.dashboard.DashboardExportAction&method=download 展开
String path = downloadFileMap.get("downPath");
res.setContentType("application/OCTET-STREAM");
OutputStream outStrem = null;
BufferedInputStream inputStream = null;
try
{
res.setHeader("Content-disposition", "attachment;filename="
+ fileName.replace(" ", "%20"));
outStrem = res.getOutputStream();
inputStream = new BufferedInputStream(new FileInputStream(path));
StreamUtils.copy(inputStream, outStrem);
inputStream.close();
outStrem.close();
}
catch (IOException e)
{
e.printStackTrace();
}
报错如下:
java.lang.IllegalStateException: STREAM
at org.eclipse.jetty.server.Response.getWriter(Response.java:920)
at com.inspur.common.http.dispatcher.ActionHelper.writeOperResult(ActionHelper.java:105)
at com.inspur.common.http.dispatcher.WebDispatcher.doPost(WebDispatcher.java:124)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:800)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:587)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:577)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:223)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1125)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:515)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1059)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97)
at org.eclipse.jetty.server.Server.handle(Server.java:497)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:310)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:248)
at org.eclipse.jetty.io.AbstractConnection$2.run(AbstractConnection.java:540)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:620)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:540)
at java.lang.Thread.run(Thread.java:745)
2015-06-24 10:39:43.960:WARN:oejs.HttpChannel:qtp22348929-102: /ajax.do?action=core.dashboard.DashboardExportAction&method=download 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询