通常在doget中

System.out.println(getServletConfig());
System.out.println(getServletConfig().getInitParameter("count1"));

这样书写时完全没有问题的,但是由于重写了init()函数,这时就发生而来异常。

先看一下init()的定义,init()是在GenericServlet中实现的【由上图可以看出,GenericServlet是httpServlet的源码】,下面是源码,

public void init(ServletConfig config) throws ServletException {
this.config = config;
this.init();
}

可以看出在init中给全局的config进行了赋值,所以通常我们在执行doget()时才可以使用config对象

所以:

在我们重写init方法是一定要记得调用父类的init方法

@Override
public void init() throws ServletException {
super.init();
/*
* 自定义内容
*/
}

因此,我的程序会报错也就不难理解了,在重写init时并没有调用父类的init(),而且也没有对config对象进行赋值,所以在doget获取的时候,只能调用到一个空的对象,在调用他的字方法时,由于它是空对象,没有被实例化,自然就会空指针异常。

getServletConfig().getInitParameter("count1") java.lang.NullPointerException的更多相关文章

  1. solr定时更新索引遇到的问题(SolrDataImportProperties Error loading DataImportScheduler properties java.lang.NullPointerException)

    问题描述 报如下错误,很显然,问题原因:空指针异常: ERROR (localhost-startStop-1) [   ] o.a.s.h.d.s.SolrDataImportProperties ...

  2. GUI学习中错误Exception in thread "main" java.lang.NullPointerException

    运行时出现错误:Exception in thread "main" java.lang.NullPointerException 该问题多半是由于用到的某个对象只进行了声明,而没 ...

  3. java.lang.NullPointerException的可能原因及处理

    java.lang.NullPointerException的可能原因及处理 java.lang.NullPointerException具体意思是空指针异常,最常见的问题就是没有初始化. 字符串等数 ...

  4. Java Web项目报错java.lang.NullPointerException at org.apache.jsp.front.index_jsp._jspInit(index_jsp.java:30)

    环境:myeclipse+tomcat6+jdk6 今天搭建了一个Java Web项目,访问index.jsp时报如下错误: 严重: Servlet.service() for servlet jsp ...

  5. jsp发布:Could not publish server configuration: null. java.lang.NullPointerException

    1.jsp发布: Could not publish server configuration: null. java.lang.NullPointerException

  6. java.lang.NullPointerException org.apache.struts2.impl.StrutsActionProxy.getErrorMessage(StrutsActionProxy.java:69)

    采用SSH框架时出现了 java.lang.NullPointerException org.apache.struts2.impl.StrutsActionProxy.getErrorMessage ...

  7. 转载java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.spinner/com.example.spinner.MainActivity}: java.lang.NullPointerException

    今天学习Android开发突然遇到了这个问题,查阅了很多资料,并且对集中原因进行了分析. 错误信息字符串:java.lang.RuntimeException: Unable to start act ...

  8. Android编译报Errors running builder 'Android Pre Compiler' on project 'XXX' java.lang.NullPointerException

    编译android时,遇到报错:Errors occurred during the build.Errors running builder 'Android Pre Compiler' on pr ...

  9. CrashHandler: java.lang.NullPointerException

    08-29 20:33:47.305 20636-20636/com.tongyan.subway.inspect D/AndroidRuntime: Shutting down VM 08-29 2 ...

随机推荐

  1. Failed to find provider info for com.tencent.mm.sdk.plugin.provider

    微信启动的时候可以调用,微信没启动,调用支付报这个错误. 我的问题是 微信发开着的jar包不是最新的,去官方网站下一个最新的就可以成功了.

  2. java以正确的方式停止线程

    java线程停止可以说是非常有讲究的,看起来非常简单,但是也要做好一些防范措施,一般停止一个线程可以使用Thread.stop();来实现,但是最好不要用,因为他是不安全的. 大多数停止线程使用Thr ...

  3. Java装箱和拆箱

    https://www.cnblogs.com/dolphin0520/p/3780005.html http://mxdxm.iteye.com/blog/2028196 装箱过程是通过调用包装器的 ...

  4. Careercup - Microsoft面试题 - 5917873302142976

    2014-05-12 06:56 题目链接 原题: A link list contains following elements struct node{ int data; node* next; ...

  5. 【Remove Nth Node From End of List】cpp

    题目: Given a linked list, remove the nth node from the end of list and return its head. For example, ...

  6. 【Two Sum】cpp

    题目: Given an array of integers, find two numbers such that they add up to a specific target number. ...

  7. MongoDB快速入门学习笔记4 MongoDB的文档查询操作

    先把student删除,再重新插入数据 > db.student.drop() true > db.student.insert([{ "_id" : 1, " ...

  8. 整理的一些Android开发类免费视频课程

    1.Android实战淘宝网项目视频:http://edu.ibeifeng.com/view-index-id-248.html 2.Android滚动视差实现课程:http://edu.ibeif ...

  9. 理解机器为什么可以学习(二)---Training versus Testing

    前边由Hoeffding出发讨论了为什么机器可以学习,主要就是在N很大的时候Ein PAC Eout,选择较小的Ein,这样的Eout也较小,但是当时还有一个问题没有解决,就是当时的假设的h的集合是个 ...

  10. linux实用命令-待补充

    - du 查看目录大小 - du -h 带有单位显示目录信息 - df 查看磁盘大小 - df -h 带有单位显示磁盘信息 - netstat 显示网络状态信息 - 清除僵尸进程 ps -eal | ...