这个错误主要是由于两次跳转所引发的 但是我的代码总通过if else 判断后只跳转了一次
private void findAllFlowCardList(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String clientId = request.getParameter("clientId"); String beginDate = request.getParameter("beginDate"); String endDate = request.getParameter("endDate"); Date dBeginDate=new Date(); Date dEndDate= new Date(); int pageNo = 1; if (request.getParameter("pageNo") != null && !"".equals(request.getParameter("pageNo"))) { pageNo = Integer.parseInt(request.getParameter("pageNo")); } int pageSize = Integer.parseInt(this.getServletContext().getInitParameter("pageSize")); try { if (beginDate != null && !"".equals(beginDate)) { dBeginDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(beginDate+ " 23:59:59"); }else { dBeginDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + " 23:59:59"); } if (endDate != null && !"".equals(endDate)) { dEndDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(endDate + " 23:59:59"); }else { dEndDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse(new SimpleDateFormat("yyyy-MM-dd").format(new Date()) + " 23:59:59"); } } catch (ParseException e) { e.printStackTrace(); } FlowCardManager flowcardManager = (FlowCardManager)BeanFactory.getInstance().getServiceObject("FlowCardManager"); PageModel pageModel = flowcardManager.findFlowCardList( pageSize, pageNo, clientId, dBeginDate, dEndDate); if(pageModel.getTotlePage() != 0) { request.setAttribute("model", pageModel); request.getRequestDispatcher("/flowcard/flow_card_maint.jsp").forward(request, response); return; }else { RequestDispatcher s= request.getRequestDispatcher("/flowcard/flow_card_maint.jsp"); s.forward(request, response); return; } } 现在发现了引起错误的原因 我写的FlowCardServlet extends BaseServlet 在baseservlet中的service方法 中super.service(request, response); 是这行代码引起了跳转 protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { command = request.getParameter("command"); user = (User)request.getSession().getAttribute("user"); // super.service(request, response); // 会引起 Cannot forward after response has been committed 提交两次请求跳转 } 现在就很不解 为啥这行代码会引发 “Cannot forward after response has been committed” ??? 请高手指教 补充:BaseServlet extends HttpServlet
|
这要看你super.service(request, response);里的代码是怎么写的,看这里能不能帮你:
你的BaseServlet中,是不是还有doGet()或者doPost(),在里面是不是已经响应给客户端了?