Results 1 to 3 of 3
- 03-23-2012, 11:41 PM #1
Member
- Join Date
- Mar 2012
- Posts
- 2
- Rep Power
- 0
Tomcat and servlets beginner question
Hi all,
I am a recently graduated compsci student and am applying for a job which requires me to write a servlet as part of the application. I have written most of the program and only need to create a servlet of a few lines to finish. The problem is I am having trouble getting Tomcat 7.0 to work and hence cannot test. I would very much appreciate some help with this problem.
I have installed Tomcat successfully and when I go to the url http://localhost:8080 the Tomcat welcome screen appears. However, when I try an click on the link to the example servlets I get a 404 not found error. I am running Windows 7 and have set my classpath variable to point to the servlet-api.jar file. The classpath reads as follows:
classpath=.;c:\Program Files\Apache Software Foundation\Tomcat 7.0\lib\servlet-api.jar
I have placed a compiled Hello World servlet under the directory:
c:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\WEB-INF\classes\HelloServlet.class
And have tried to access it with the url:
http://localhost:8080/servlet/HelloServlet
But I get the 404-not found error. I have tried for many hours to get it working to no avail. Is there something else I need to do to get servlets working with Tomcat 7.0?
Thanks
- 03-24-2012, 02:31 AM #2
Senior Member
- Join Date
- Jun 2007
- Location
- Bali, Indonesia
- Posts
- 762
- Rep Power
- 14
Re: Tomcat and servlets beginner question
When creating a servlet, beside creating the servlet class itself you must register the servlet in your web application. This can be done by either registering your servlet in the web.xml or using the @WebServlet annotation.
Website: Learn Java by Examples
- 03-24-2012, 02:49 AM #3
Member
- Join Date
- Mar 2012
- Posts
- 2
- Rep Power
- 0
Re: Tomcat and servlets beginner question
Thankyou very much wsaryada. I now have it working by defining a servlet-mapping in the web.xml file. Previous versions of Tomcat I have used had an invoker servlet which I was tearing my hair out trying to find in Tomcat 7, but I guess this invoker is no longer used and servlets must be mapped manually. Thanks again.
Similar Threads
-
applet and mysql in jsp using tomcat servlets
By gedas in forum Java AppletsReplies: 4Last Post: 04-05-2011, 10:41 PM -
simple question about servlets
By kulangotski in forum Java ServletReplies: 2Last Post: 01-06-2011, 10:50 AM -
Ubuntu 10.10 Tomcat 6 & Servlets newbie
By midnight1111 in forum Java AppletsReplies: 1Last Post: 12-07-2010, 09:59 AM -
running servlets in tomcat
By mipravin in forum Java ServletReplies: 4Last Post: 03-18-2009, 12:17 PM -
question on servlets
By Minu in forum Java ServletReplies: 4Last Post: 01-16-2009, 11:21 AM
Bookmarks