下面的方法抛出:Servlet DetailCakeServlet 的 Servlet.service() 抛出异常
java.lang.IllegalStateException: Cannot forward after response has been committed.
代码
try (PrintWriter out = response.getWriter()) {
/* TODO output your page here. You may use following sample code. */
CakeDAO dao = new CakeDAO();
String strID = request.getParameter("id");
int id = Integer.parseInt(strID);
request.setAttribute("cake", dao.getCakeById(id));
request.getRequestDispatcher("/WEB-INF/detail.jsp").forward(request, response);
}catch (Exception ex) {
request.getRequestDispatcher("/WEB-INF/error.jsp").forward(request, response);
}
但是当我删除资源对象时,它就可以工作了。可能是什么原因 ?
神不在的星期二
函数式编程
相关分类