• Post Reply Bookmark Topic Watch Topic
  • New Topic

My first servlet program -execution

 
Vishwanath Krishnamurthi
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ranchers,

I am just starting with servlets now and tried this program:
(from complete reference java, Herbert Schildt)




I compiled this and placed the class file in
f:\tomcat\webapps\try\WEB-INF\classes\

Then tried
http://localhost:8080/try/servlet/HelloServlet in the browser...

and all I get is a HTTP Status 404 with the description:The requested resource (/try/servlet/HelloServlet) is not available.

Can you please guide me...

http://localhost:8080/ works fine though, I am able to see the default tomcat page and was able to execute the servlet examples provided by tomcat...

So I'm assuming that I've specified JAVA_HOME, CATALINA_HOME variables properly...
 
Siddharth Naik
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It appears that you are trying to create a web application.
In that case: extend HttpServlet, override doGet() or doPost()methods and use HttpServletRequest and HttepServletResponse objects as parameters.


http://java.sun.com/developer/onlineTraining/Programming/BasicJava1/servlet.html
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing that's a pretty old book.
From the URL, I'm assuming that it's assuming that you have the InvokerServlet enabled. In all the the oldest versions of Tomcat that feature has been disabled.

If the book covers creating servlet entries and servlet mappings in web.xml, try doing that and see if it works. If not, we have demo application that's all packaged up and ready to go in our codeBarn.
Download SimpleServlet.war to your TOMCAT/webapps directory and Tomcat will unpack and deploy the application for you. Once it does, you can look at TOMCAT/webapps/SimpleServlet/WEB-INF/web.xml to see how it was done.

Hope this helps.
 
Vishwanath Krishnamurthi
Ranch Hand
Posts: 331
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

thanks... Ya, thats an old book... Earlier I had tried an example from "Head first Servlets & JSP" and that wasn't working too...
I had done some mistakes in web.xml while typing, I guess... Tried editing the web.xml in this codebarn servlet example and used it... and it works perfectly now!

thanks...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!