HTTP Status 500 - Cannot call sendRedirect() after the response has been committed
主要是 sendRedirect()执行完之后没有结束,还会继续往下执行,所以sendReirect()后面就不要在sendReirect()了。
if(type.equals("0")){
... response.sendRedirect("cart.jsp");}else if(type.equals("1")){ ... response.sendRedirect("cart.jsp");}else if(type.equals("2")){...response.sendRedirect("cart.jsp");}else if(type.equals("3")){...response.sendRedirect("success.jsp");}response.sendRedirect("index.jsp");
要么每次sendRedirect之后return 要么再放个else
本文探讨了HTTP状态码500错误中关于sendRedirect()方法的常见问题,即在响应已提交后调用此方法导致的问题。通过示例代码展示了如何正确地使用sendRedirect()来避免此类错误。
40万+

被折叠的 条评论
为什么被折叠?



