Usually in Doget.
System.out.println (Getservletconfig ()); System.out.println (Getservletconfig (). Getinitparameter("Count1"));
There is absolutely no problem in writing this, but because the init () function is rewritten, this happens unexpectedly.
First look at the definition of init (), Init () is implemented in the Genericservlet "can be seen, Genericservlet is HttpServlet source", the following is the source,
Public void throws servletexception { this. config = config; This . Init (); }
We can see that the Global config is assigned in init, so we usually use the Config object when we execute Doget ().
So:
before we rewrite the Init method, be sure to remember to call the parent class's Init method
@Override Public void throws servletexception { super. Init (); /* * Customize content * / }
Therefore, my program will not be difficult to understand the error, in the rewrite Init did not call the parent class init (), and also did not assign a value to the Config object, so when Doget gets, can only call to an empty object, when calling his word method, because it is an empty object, is not instantiated , you will naturally have null pointer exceptions.
Getservletconfig (). Getinitparameter ("Count1") java.lang.NullPointerException