I created a Servlet and when i started to run it in localhost, it immediately access the doGet() method and throws error I have given.
I don't see how any servlet will run the doGet() method unless there's a request coming in. Of course the servlet's init() method can potentially be called without any requests, but not the doGet() method. Furthermore, you seem to indicate in your later reply that you are seeing that message in a browser, which effectively means that the user of that browser triggered that request.
I mentioned about the 404, No such users found error.
I don't see where you had mentioned that, but that's irrelevant now that we know what happens. That message would be an expected outcome if the username/password passed to the servlet did not match an actual user, or if no parameters were passed to it. I'm confused by you saying you "right-clicked" on something to run the servlet. You would need an HTML form for entering the parameters, or you would have to add the parameters to the URL for this to work - which one of these are you trying to make work?
I want the get method and post method to be executed when i call it from my client
A "client" is a browser, or code that accesses this servlet programmatically?
(A couple of side notes: This code must not be used in a production setting as it is wide open to SQL injection attacks; use a PreparedStatement in lines 71-73 to guard against that. It also passes credentials via a GET, which is another security problem. And it uses GET and POST interchangeably, which generally violates the HTTP specification - I'd really like to find out who started this nonsense with a processRequest method that is called from both doGet and doPost; that person ought to be taken out back and shot for crimes against software engineering.)
As I already mentioned, I haven't started my client yet. The error message comes once I run the servlet from Netbeans.
Has this happened to any one?
Joined: Mar 22, 2005
Let me put it another way: You click on something that apparently says "run servlet", and then you are surprised that the servlet runs - what else did you expect?
This is part of the reason that I advise beginners not to use an IDE for servlet development until they understand web apps and servlet containers - people tend to battle the IDE more than heir servlets.
It looks like you are learning Servlets and trying to understand how all the pieces work together. I think it's a good time to pick one of the books on Servlets to understand this better. Like Ulf says, it's a good idea to stay away for the IDE integration for developing web applications, till you understand the basics.