用管理员身份登陆修改物品信息提示: Servlet.service() for servlet changeservlet threw exception
提示以下错误:
严重: Servlet.service() for servlet changeservlet threw exception
java.lang.NumberFormatException: For input string: "70.0"
at java.lang.
NumberFormatException.forInputString(NumberFormatException.java:48)
at java.lang.Integer.parseInt(Integer.java:458)
at java.lang.Integer.parseInt(Integer.java:499)
at servlet.changeservlet.doPost(changeservlet.java:23)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:602)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
找到相应的代码处:
String title =request.getParameter ("title");
String imagefile =request.getParameter ("imagefile");
String isbn =request.getParameter ("isbn");
int price =Integer.parseInt(request.getParameter ("price"));
int editionnumber =Integer.parseInt(request.getParameter("editionnumber"));
int copyright =Integer.parseInt(request.getParameter ("copyright"));
UserDao userDao = new UserDao();
UserregisterDao userregisterDao = new UserregisterDao();
User user =new User();
user.settitle(title);
user.setimagefile(imagefile);
user.setisbn(isbn);
user.setprice(price);
user.seteditionnumber(editionnumber);
user.setcopyright(copyright);
HttpSession session = request.getSession(true);
changeDao change=new changeDao();
try
{
change.change(title, imagefile, isbn, price, editionnumber, copyright);
}
catch(Exception e){
log("Error");
}
servlet
session
exception
------解决方案--------------------数据格式类型转换错误,找到对应的字段名,进行相应的格式转换操作即可。
------解决方案--------------------java.lang.NumberFormatException: For input string: "70.0"数字格式化错误。
改为这样试试,Integer.parseInt转换,不能有空格和非数字字符
int price =Integer.parseInt(r