Tomcat v9.0 服务器在 eclipse EE 上启动失败

问题描述 投票:0回答:1

如果我在 web.xml 文件中创建 servlet 和 servlet 映射,Tomcat 9.0 服务器无法启动,如果我删除 web.xml 文件上的 servlet 和 servlet 映射,服务器正在运行?

为什么会发生这种情况?

我尝试使用 tomcat v9.0 服务器使用 servlet 运行我的 Web 应用程序,如果我在 web.xml 文件上添加 servlet 和映射,服务器将无法启动。如果我删除了我的 servlet 和 web.xml 上的映射,并通过注释“@WebServlet(/xxx)”进行映射,服务器正在启动,但在网页上提交客户端请求时,它会显示错误页面 - 如下所示。

HTTP Status 500 – Internal Server Error
Type Exception Report

Message Cannot invoke "String.trim()" because "in" is null

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

java.lang.NullPointerException: Cannot invoke "String.trim()" because "in" is null
    java.base/jdk.internal.math.FloatingDecimal.readJavaFormatString(FloatingDecimal.java:1838)
    java.base/jdk.internal.math.FloatingDecimal.parseDouble(FloatingDecimal.java:110)
    java.base/java.lang.Double.parseDouble(Double.java:651)
    controller.SaveServlet.doPost(SaveServlet.java:24)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:555)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:623)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
Note The full stack trace of the root cause is available in the server logs.

Apache Tomcat/9.0.86
eclipse servlets jakarta-ee nullpointerexception tomcat9
1个回答
0
投票

在执行

NullPointerException
时,您在方法
doPost
中获得了
Double.parseDouble(null)
。为什么参数是
null
?因为它没有随请求一起发布,并且
requrst.getParameter
返回
null
。在将参数分配给变量之前,您应该检查请求中的
null
参数是否存在。

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.