not able to run a servlet

Posted on 2006-04-28
Last Modified: 2013-11-24
the steps i did to run a servlet is given below but I get Http 404 error

I have set the CLASSPATH to servlet-api.jar and got it compiled
1.The HelloWWW class file is in HOME\webapps\shop\shops\WebRoot\WEB-INF\classes.

2. in web.xml I have made the flg changes
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"



3.when I run the flg path in my browser I get the flg error
ERRORHTTP Status 404 - /shop/shops/WebRoot/locator file not available

Please help
Question by:cakurien
    LVL 30

    Expert Comment

    Try adding your class to a package, like mypackage.HelloWWW

    Then use: <servlet-class>mypackage.HelloWWW</servlet-class>

    Also, the HelloWWW class-file will go under the classes\mypackage folder.
    LVL 23

    Accepted Solution

    LVL 23

    Expert Comment


    is this correct???

    what's your Web Project name??? (shop???)

    try http://localhost:8080/shop/locator

    Thank You.

    Expert Comment

    Your appserver is will first try to match your web application context before matching your servlet path.  Therefore, if you application context is "shop", then the app server will try to match the rest of your url to a servlet.  The rest of the url (without shop) for the url you tried is now "/shops/WebRoot/locator".  Since this has no servlet mapping it will try "/shops/WebRoot" and then "/shops".  None of these have url mapping to servlets.  Therefore, you should try the url mentioned above.


    Other urls such as http://localhost:8080/shop/locator/something/something should work also.
    LVL 5

    Expert Comment

    LVL 5

    Expert Comment

    LVL 27

    Expert Comment

    Please tell us which web app server you are using.  Is it Tomcat ?  I will presume so.
    Anyway your file structure is wrong.  
    The WEB-INF directory must be a subdirectory of webapps. Otherwise Tomcat will not even recognize it as a web app. You can see this if you use Tomcat's manager( ask us if need help setting it up).    So, if  WebRoot is your context then  put  your HelloWWW class file  into  
    HOME\webapps\WebRoot\WEB-INF\classes.   and then use   http://localhost:8080/WebRoot/locator  in your browser.    
    As suggested by mayankeagle it is good practice to use packages. But they are not required( see first link posted by shivaspk) for servlets. Packages are required for javabeans but that another lesson.   rrz
    LVL 27

    Expert Comment

    >The WEB-INF directory must be a subdirectory of webapps  
    I am sorry. I meant to say that your WEB-INF must be a subdirectory of your context. Your context is a subdirectory of webapps.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
    Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now