java web开发下载时候报错,
download1.jsp<body>文件下载<hr><ahref="download.jsp?file=yangshengfangfadajiemi.chm">下载</...
download1.jsp
<body>
文件下载
<hr>
<a href="download.jsp?file=yangshengfangfadajiemi.chm">下载</a>
</body>
download.jsp
<body>
<%
String filename = request.getParameter("file");
// 告诉客户端出现下载框,并制定下载框中的文件名
response.setHeader("Content-Disposition","attachment;filename="+filename);
// 指定文件类型
response.setContentType("application/octet-stream");
// 指定文件
RequestDispatcher rd = request.getRequestDispatcher("/FILES/" + filename);
rd.forward(request,response);
%>
</body>
浏览器访问时候后台报错如下:
严重: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response 展开
<body>
文件下载
<hr>
<a href="download.jsp?file=yangshengfangfadajiemi.chm">下载</a>
</body>
download.jsp
<body>
<%
String filename = request.getParameter("file");
// 告诉客户端出现下载框,并制定下载框中的文件名
response.setHeader("Content-Disposition","attachment;filename="+filename);
// 指定文件类型
response.setContentType("application/octet-stream");
// 指定文件
RequestDispatcher rd = request.getRequestDispatcher("/FILES/" + filename);
rd.forward(request,response);
%>
</body>
浏览器访问时候后台报错如下:
严重: Servlet.service() for servlet jsp threw exception
java.lang.IllegalStateException: getOutputStream() has already been called for this response 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询