jQuery in Action, 3rd edition
The moose likes Servlets and the fly likes not getting responce from Servlet  Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "not getting responce from Servlet  " Watch "not getting responce from Servlet  " New topic

not getting responce from Servlet

vendikonda sravan
Ranch Hand

Joined: May 09, 2010
Posts: 38

i have written a small basic servlet

which takes responce from the index.html

and web.xml file
and my Servlet class is Servlet1
i'm using my eclips with tomcat. can some buddy help were it's goin wronge.
Tom Reilly

Joined: Jun 01, 2010
Posts: 618
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.
Hebert Coelho
Ranch Hand

Joined: Jul 14, 2010
Posts: 754

Hello vendikonda sravan,

If you want a simple tutorial of how build a webserver with servlet you can take a look at a link in my signature.

And be sure to understand everything Tom Reilly said.

[uaiHebert.com] [Full WebApplication JSF EJB JPA JAAS with source code to download] One Table Per SubClass [Web/JSF]
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 547


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.


vendikonda sravan
Ranch Hand

Joined: May 09, 2010
Posts: 38

thanks every buddy kumar was right the pronlem was in html the problem is solved.
Thanks alot guys
I agree. Here's the link: http://aspose.com/file-tools
subject: not getting responce from Servlet
It's not a secret anymore!