创建servlet 时 未去掉 ServletConfig config 报错


最近在学习Javaweb项目 ,创建一个初始化servlet时 按照步骤来.如下图所以.只勾选init  .创建成功后.在 init(ServletConfig config) 中 ServletConfig config没有去掉 

在启动Apache Tomact 时 ,.但是也能够启动,.能够正常访问.

报以下错误:


严重: StandardWrapper.Throwable

java.lang.NullPointerException

at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:123)

at com.rf.servlet.InitServlet.init(InitServlet.java:16)

at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1227)

at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1140)

at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1027)

at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5037)

at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5347)

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)

at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3868)

at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:290)

at org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:5670)

at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1377)

at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1381)

at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1381)

at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1349)

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


二月 07, 2018 3:41:33 下午 org.apache.catalina.core.StandardContext loadOnStartup

严重: Servlet [InitServlet] in web application [/reg] threw load() exception

java.lang.NullPointerException

at javax.servlet.GenericServlet.getServletContext(GenericServlet.java:123)

at com.rf.servlet.InitServlet.init(InitServlet.java:16)

at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1227)

at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1140)

at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1027)

at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5037)

at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5347)

at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:145)

at org.apache.catalina.core.StandardContext.reload(StandardContext.java:3868)

at org.apache.catalina.loader.WebappLoader.backgroundProcess(WebappLoader.java:290)

at org.apache.catalina.core.StandardContext.backgroundProcess(StandardContext.java:5670)

at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1377)

at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1381)

at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1381)

at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1349)

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




image.png

image.png



去除以后 ,没有再报错.正常启动  !!





来源: up61技术博客 欢迎分享 (QQ:529857614)

qq交流群:63739043 up61博客-php交流群

上一篇: php.ini 配置调优 —— 让 PHP 应用性能维持在更高水平
下一篇: servlet 获取请求参数的值


评论