java.lang.NumberFormatException: null 错误
我是根据书上写的代码,启动Tomcat后,输入的是网址是http://localhost:8080/Test/servlet/CounterServlet网页上出现结果了,可是MyEclipse报错了,有哪位高手指点一下不胜感激。
java.lang.NumberFormatException: null
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at TestOne.CounterServlet.init(CounterServlet.java:36)
at javax.servlet.GenericServlet.init(GenericServlet.java:212)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:809)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Unknown Source)
MyEclipse中的代码:
public class CounterServlet extends HttpServlet {
int counter = 0;// 设点击数是0
int org = 5;// 设初始的配置的点击数值是5
@Override
/**
* 处理doGet请求
*/
protected void doGet(HttpServletRequest req, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=gb2312");// 设置编码格式
PrintWriter out = response.getWriter();
counter++;
out.print("自从这个Servlet载入,它已经被访问了" + counter + "次,加上初始的配置,"
+ "这个Servlet共被访问了" + (org + counter) + "次");
}
/**
* 初始化方法,获得初始化参数
*/
@Override
public void init() throws ServletException {
String c = getInitParameter("conter");
try {
org = Integer.parseInt(c);
} catch (Exception e) {
e.printStackTrace();
}
}
}
搜索更多相关主题的帖子:
java lang null
----------------解决方案--------------------------------------------------------
conter,看看你的servlet的配置中是不是没有配置这个初始化参数,使得在这里获得
String c = getInitParameter("conter");
c是一个null,所以线面的parseInt报出parse失败的异常。
----------------解决方案--------------------------------------------------------
String c = getInitParameter("conter"); //是counter 还是conter?
----------------解决方案--------------------------------------------------------
,感谢各位的帮助。我是根据《JSP应用开发详解(第三版)》P131写的,可是在书上我没有发现让我配置Servlet呀,各位有什么好的jsp书籍给我推荐一下,我这里不胜感激,谢谢
----------------解决方案--------------------------------------------------------
数字格式化异常 String c = getInitParameter("conter") 中 你那‘conter’从哪来的啊 去看看它吧
----------------解决方案--------------------------------------------------------