Results 1 to 3 of 3
  1. #1
    iparry is offline Member
    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Default 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

  2. #2
    wsaryada is offline Senior Member
    Join Date
    Jun 2007
    Location
    Bali, Indonesia
    Posts
    760
    Rep Power
    8

    Default 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.

  3. #3
    iparry is offline Member
    Join Date
    Mar 2012
    Posts
    2
    Rep Power
    0

    Default 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

  1. applet and mysql in jsp using tomcat servlets
    By gedas in forum Java Applets
    Replies: 4
    Last Post: 04-05-2011, 10:41 PM
  2. simple question about servlets
    By kulangotski in forum Java Servlet
    Replies: 2
    Last Post: 01-06-2011, 10:50 AM
  3. Ubuntu 10.10 Tomcat 6 & Servlets newbie
    By midnight1111 in forum Java Applets
    Replies: 1
    Last Post: 12-07-2010, 09:59 AM
  4. running servlets in tomcat
    By mipravin in forum Java Servlet
    Replies: 4
    Last Post: 03-18-2009, 12:17 PM
  5. question on servlets
    By Minu in forum Java Servlet
    Replies: 4
    Last Post: 01-16-2009, 11:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •