• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

not getting responce from Servlet

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI,

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.
 
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 754
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 558
2
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sravan,

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
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

thanks every buddy kumar was right the pronlem was in html the problem is solved.
Thanks alot guys
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic