HttpServlet中init()重写时出现NullPointerException
来源:互联网 发布:java医疗项目需求文档 编辑:程序博客网 时间:2024/05/29 07:21
原代码如下:
public class ServletDemo extends HttpServlet {
private static final long serialVersionUID = 1L;
private ServletConfig sercon;
public ServletConfig getSercon() {
return sercon;
}
public void setSercon(ServletConfig sercon) {
this.sercon = sercon;
}
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
@Override
public void init(ServletConfig config) throws ServletException {
this.sercon=config;
String str=sercon.getInitParameter("data");
System.out.println(str);
//直接用父类的定义getServletConfig()
sercon=this.getServletConfig();
String str1=sercon.getInitParameter("data1");
System.out.println(str1);
}
}
以上代码(部分代码)会出现NullPointerException异常
解决方法是在重写是加上:super.init(config);
- HttpServlet中init()重写时出现NullPointerException
- android中调用findViewById时出现:java.lang.NullPointerException
- 在servlet的init方法中使用getServletConfig、getServletContext时发生nullpointerexception
- Android 开发中出现java.lang.NullPointerException
- Eclipse中使用butterknife出现nullPointerException
- IDE中使用Console出现NullPointerException错误
- 在继承HttpServlet时,为什么只重写doGet和doPost
- ButterKinfe.bind(this) @BindView时出现NullPointerException
- Android RelativeLayout.mesure()时出现NullPointerException异常
- JavaWeb项目在MyEclipse中调试出现java.lang.NullPointerException异常时的处理
- Fragment中出现java.lang.NullPointerException 空指针 上下文为空时
- Android中利用NetworkInfo判断网络状态时出现空指针(NullPointerException)问题解决
- OC中init方法的重写和自定义
- spring工程中为什么会出现HibernateTemplate的NullPointerException异常
- Struts2中 出现Exception starting filter struts2 java.lang.NullPointerException
- 在action中调用去出现java.lang.NullPointerException错误
- Java中不注意出现的java.lang.NullPointerException
- Java中出现了一个不知原因的NullPointerException
- 身为程序员的你是不是经常说这几句话呢?
- AndroidStudio如何引入so包
- javascript语句和表达式
- Ubuntu修改etc/environment文件后无法登陆系统的问题解决办法
- 测试小工具1:同时打开多个相机(多线程)
- HttpServlet中init()重写时出现NullPointerException
- 在 Mac OS X 上安装 TensorFlow
- Python 科学计算库 Numpy 准备放弃 Python 2 了
- 趣图:典型的软件开发流程
- 新登月计划!阿里云ET城市大脑成为国家AI开放创新平台
- MySQL数据库--外键约束及外键使用
- 用Construct2制作你的第一款游戏
- Android异步消息处理机制
- hashcode()与equals()