java.lang.NumberFormatException: null报错

java.lang.NumberFormatException: null报错


ProductServlet  代码

private void delete(HttpServletRequest request, HttpServletResponse response) throws IOException {

//接收数据

Integer pid =  Integer.parseInt(request.getParameter("pid"));

//调用业务成处理数据

ProductService productService = new ProductServiceImpl();

productService.delete(pid);

//页面跳转

response.sendRedirect(request.getContextPath()+"/ProductServlet?method=findAll");

}


ProductDaoImpl 代码

@Override

public void delete(Integer pid) {

Connection conn = null;

PreparedStatement pstmt = null;

try {

//获得连接

conn = JDBCUtils.getConnection();

//编写SQL

String sql = "delete from product where pid=?";

//预编译SQL

pstmt = conn.prepareStatement(sql);

//设置参数

pstmt.setInt(1, pid);

//执行SQL

int i = pstmt.executeUpdate();

if(i>0) {

System.out.println("成功");

}

}catch(Exception e) {

e.printStackTrace();

}finally {

JDBCUtils.release(pstmt, conn);

}

}

报错代码

严重: Servlet.service() for servlet [com.imooc.web.action.ProductServlet] in context with path [/shop] threw exception

java.lang.NumberFormatException: null

at java.lang.Integer.parseInt(Unknown Source)

at java.lang.Integer.parseInt(Unknown Source)

at com.imooc.web.action.ProductServlet.delete(ProductServlet.java:52)

at com.imooc.web.action.ProductServlet.doGet(ProductServlet.java:40)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:634)

at javax.servlet.http.HttpServlet.service(HttpServlet.java:741)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

at com.imooc.web.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:31)

at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)

at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)

at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)

at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)

at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:528)

at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139)

at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)

at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)

at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)

at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)

at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)

at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)

at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:810)

at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1498)

at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)

at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)

at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

at java.lang.Thread.run(Unknown Source)


正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

1回答
提问者 紧张 2019-11-15 15:44:39

eee    已解决

  • 同学能自己解决问题,也是一种进步。继续加油。祝:学习愉快~
    2019-11-15 16:32:20
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师