当前位置: 代码迷 >> J2EE >> java.lang.IllegalStateException。请求相助
  详细解决方案

java.lang.IllegalStateException。请求相助

热度:452   发布时间:2016-04-22 03:42:57.0
java.lang.IllegalStateException。请求帮助
写了个Servlet,当request.getParameter("num") 中传递来的num是一个非数字时,我觉得应该catch到后跳转到response.sendRedirect("sysError.html");了,可为什么会报
request.getRequestDispatcher("viewCart.jsp").forward(request, response);有错java.lang.IllegalStateException
这个错我也看不懂是啥意思。

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html;charset=gbk");
request.setCharacterEncoding("gbk");
HttpSession session = request.getSession();
Map<String,CartItemBean> cart = (HashMap<String, CartItemBean>)session.getAttribute("cart");
try {
String isbn = request.getParameter("isbn");
int num = Integer.parseInt(request.getParameter("num"));
CartItemBean item = cart.get(isbn);
if(item.getQuantity() - num >= 1){
item.setQuantity(item.getQuantity()-num);
}
else{
cart.remove(isbn);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
response.sendRedirect("sysError.html");
}
request.getRequestDispatcher("viewCart.jsp").forward(request, response);
}


------解决方案--------------------
catch最后加个return;
  相关解决方案