• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 197
  • Last Modified:

not able to run a servlet

the steps i did to run a servlet HelloWWW.java 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"
      xmlns="http://java.sun.com/xml/ns/j2ee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
      http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>anyname</servlet-name>
<servlet-class>HelloWWW</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>anyname</servlet-name>
<url-pattern>/locator</url-pattern>
</servlet-mapping>

</web-app>

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

Please help
0
cakurien
Asked:
cakurien
  • 2
  • 2
  • 2
  • +2
1 Solution
 
Mayank SAssociate Director - Product EngineeringCommented:
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.
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
0
 
Siva Prasanna KumarPrincipal Solutions ArchitectCommented:
>>http://localhost:8080/shop/shops/WebRoot/locator

is this correct???

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

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

Thank You.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
leobaz2Commented:
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.

http://localhost:8080/shop/locator

Other urls such as http://localhost:8080/shop/locator/something/something should work also.
0
 
mrigankCommented:
0
 
mrigankCommented:
0
 
rrzCommented:
Please tell us which web app server you are using.  Is it Tomcat ?  I will presume so.
Anyway your file structure is wrong.  
>HOME\webapps\shop\shops\WebRoot\WEB-INF\classes.
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
0
 
rrzCommented:
>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.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now