Problem in servlets

I have a Login-page (a JSP) in which the user enters the username
and password. The JSP is submitted using METHOD=“POST”. In the
servlet I have all the logic written in the doPost() method, the
doGet() method just forwards the control to the doPost method. After
the user credentials are validated in the doPost method the user is
fwded to a different JSP, if not then the same login page is
displayed. The problem is that once the doPost method has been
executed the doGet is being called automatically (so doPost is being
called 2 times, once by the request and once by doGet), the second
time a NullPointerException is thrown (since there is no
username/pwd to validate).

I am confused as to why doGet is being called automatically!

Ok, this is a guess, but since nobody else has replied I will take a shot.

Those methods are probably called every time. They PROBABLY dont’ care if you are doing a get or a post. So you don’t want to have your code designed the way you do if you plan on handling both. You know that you are going to do a POST and not a GET so just do the POST.

Again this is a guess.

Now you could also take the cheap way out and just have the Login page post to another JSP. Call that JSP something like LoginCheck.jsp and just do your code there. It will get compiled to a servlet.