javaweb 求教!!Integer.parseInt()异常问题
if(!request.getParameter("bookprice").trim().equals(""))
try{
book.setPrice(Integer.parseInt(request.getParameter("bookprice")));
}catch(Exception e)
{
System.out.println("对不起,只能输入整数,请重新输入。") ;
}
我输入字符串之后显示500异常,刚学javaweb 求指教!!
HTTP Status 500 - For input string: "1k"
type Exception report
message For input string: "1k"
description The server encountered an internal error that prevented it from fulfilling this request.
exception
java.lang.NumberFormatException: For input string: "1k"
java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
java.lang.Integer.parseInt(Integer.java:580)
java.lang.Integer.parseInt(Integer.java:615)
Action.BookAction.EditDone(BookAction.java:149)
Action.BookAction.doGet(BookAction.java:45)
Action.BookAction.doPost(BookAction.java:19)
javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
note The full stack trace of the root cause is available in the Apache Tomcat/8.5.9 logs.