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.(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();
}
}
}