MyException - 我的异常网
当前位置:我的异常网» J2EE » java.lang.IllegalStateException。请求相助

java.lang.IllegalStateException。请求相助

www.MyException.Cn  网友分享于:2013-11-11  浏览:315次
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;

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有