This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
A few observations:
1. You instantiate an instance of Servlet1 in your doPost() method of Servlet1. You never need to create instances of your Servlet classes. The web container (Tomcat) will do this for you.
2. Your Servlet should not have instance variables since Servlets must support multiple threads.
3. You're Servlet is probably throwing a null pointer exception (NPE) since you are trying to use an instance of Servlet1 that has not initialized the String instance variables (I could be wrong about the NPE, but the code certainly won't do what you intend it to do.)
4. You are working with two instances of Servlet1; the one the container created and the one you created. You are assigning your parameters to instance variables of the container-created Servlet1 but trying to use the instances variables from the Servlet1 instance that you created.
Since you are using Eclipse, I suggest you put a breakpoint in the doPost() method and step through the code.
You can also look at the Tomcat log files or its console output.
I think your real problem is in your jsp/html page. If you look at the clearly, your submit is outside <Form>. I doubt if you are even triggering the servlet. Try moving the submit inside <form> element and it should work.
Technically, compiler would not complain, if you instantiate your servlet. However, as Tom pointed out, you really don't need to do that. Since servlet is managed by container only, the task needs to be left to the container.
Joined: May 09, 2010
thanks every buddy kumar was right the pronlem was in html the problem is solved.
Thanks alot guys