javaweb 求教!!Integer.parseInt()异常问题

Goback丶 2019-10-17 04:20:05
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.
...全文
191 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Goback丶 2019-10-17
  • 打赏
  • 举报
回复
对 我知道,可是我抛出异常了啊 应该会显示"对不起,只能输入整数,请重新输入。"怎么编写可以解决呢
jio可 2019-10-17
  • 打赏
  • 举报
回复
错误提示输入的1k

5,657

社区成员

发帖
与我相关
我的任务
社区描述
Web开发应用服务器相关讨论专区
社区管理员
  • 应用服务器社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧