2015-08-24 118 views
0

我試圖重定向到成功完成任務後一個JSP,但我收到以下錯誤:IllegalStateException異常在org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:463)

java.lang.IllegalStateException 
at org.apache.catalina.connector.ResponseFacade.sendRedirect(ResponseFacade.java:463) 

我已經嘗試了大部分的步驟,正如互聯網上所解釋的,但其中一些步驟沒有意義。

下面是我在做什麼:

  --- In Servlet --- 

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 
    // TODO Auto-generated method stub 

    String action = request.getParameter("action"); 

    HttpSession session = request.getSession(); 

    if(action.equals("Complete Order")) 
    { 
     CartItems[] obj = (CartItems[])session.getAttribute("Cart"); 

     OrderDAO od = new OrderDAO(); 

     for(int i=0;i<obj.length;i++) 
     { 
      od.insert_order(obj[i]); 
      String[] t = od.getOrderIDs(obj[i].getOrder_Date(),obj[i].getUserID()); 

      int len = (t.length); 

      System.out.println(len); 

      int l = Integer.parseInt(t[len-1]); 

      System.out.println(l); 

      od.insert_order_details(obj[i] ,l); 

      response.sendRedirect(".\\userordercomplete.jsp"); 

     } 
    } 
    else if(action.equals("Cancel Order")) 
    { 
     session.setAttribute("Cart", null); 
     response.sendRedirect(".\\user.jsp"); 

    } 

    doGet(request, response); 
} 

回答

2

的問題是你一直保持重定向調用內部的for循環,完成一切,最後

for(int i=0;i<obj.length;i++) 
    { 
     // your stuff 

    } 
    response.sendRedirect(".\\userordercomplete.jsp"); 
重定向
相關問題