我正在为我的简单应用程序使用 Servlet 和 Jsp。当我单击提交按钮时,它会调用服务器并下载 PDF 文件并将其转发到下一页。现在我的问题是我 response.setHeader and getOutputStream
在我的 servlet 中使用,同时我试图将我的请求转发到下一页。现在它向我抛出错误说 java.lang.IllegalStateException: Cannot forward after response has been committed
。请任何人都可以帮我解决这个问题。
代码:
public class Class extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
Document document = new Document();
ServletConfig cfg=getServletConfig();
ServletContext application=cfg.getServletContext();
response.setContentType("application/pdf");
response.setHeader("Content-Disposition"," attachment; filename=\"BI_Staffing.pdf\"");
PdfWriter writer = PdfWriter.getInstance(document, response.getOutputStream());
------------
---------------(My Code)
document.close();
RequestDispatcher rd=request.getRequestDispatcher("staffing-results1.jsp");
rd.forward(request,response);
}
}