我正在尝试在成功完成任务后重定向到jsp但是我收到以下错误:
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);
}
答案 0 :(得分:2)
问题是你在for循环中保留了重定向调用,完成所有操作并最后重定向
for(int i=0;i<obj.length;i++)
{
// your stuff
}
response.sendRedirect(".\\userordercomplete.jsp");