Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

Servlet Not running. Getting the message HTTP Status 404..

Dear Experts-

Before I post this question, I have read threads related to this issue. I still face this problem.

This is related to servlets.Please guide me. I don't know where it was going wrong. I could able run my JSP with out any issues.

1. I am getting following message

MyURL : http://localhost:8080/MyApplication/servlet/coreservlets.HelloWWW

HTTP Status 404 - /MyApplication/servlet/coreservlets.HelloWWW

type Status report

message /MyApplication/servlet/coreservlets.HelloWWW

description The requested resource (/MyApplication/servlet/coreservlets.HelloWWW) is not available.

My folder structure:

C:\Program Files\Apache Group\Tomcat 4.1\webapps\MyApplication\WEB-INF\classes\coreservlets

classpath :

C:\Program Files\Apache Group\Tomcat 4.1\webapps\MyApplication\WEB-INF\classes;
C:\Program Files\Apache Group\Tomcat 4.1\common\lib\servlet.jar

Thank you
0
akp007
Asked:
akp007
  • 4
  • 3
  • 2
3 Solutions
 
bloodredsunCommented:
What does your web.xml look like? Have you mapped this servlet in the web.xml? if you haven't, you will need to map the servlet similar to this example http://www.murach.com/books/jsps/questions.htm
0
 
akp007Author Commented:
Wow! Great. I removed the commnet as mentioned in the url you mentioned , My code is working. But I have a question.
1.   Right now I don't have web.xml under C:\Program Files\Apache Group\Tomcat 4.1\webapps\MyApplication\WEB-INF\.
2.   Still my code is working by removing the comment from  "  <!-- The mapping for the invoker servlet -->" in
      Tomcat  4.1\conf\web.xml.
3.  But do we need to have web.xml under the current apllication directory. Because I have seen one under examples directory

Thanks

0
 
bloodredsunCommented:
1./Because you are accessing the servlet directly through the invoker servlet as you have said! If you moved your webapp to another server it would not work. That is why you need to create a web.xml under the webapp and you can call it a different name
2./as above
3./as above

Glad you have helped
0
Industry Leaders: 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!

 
akp007Author Commented:
What I did was I created a web.xml  under C:\Program Files\Apache Group\Tomcat 4.1\webapps\MyApplication\WEB-INF, then my JSP are not working. Any suggestions.

Thanks
0
 
bloodredsunCommented:
Probably because your web.xml is faultly. It can't be a copy of the one in tomcat/conf but you need to create one just for your web app.
0
 
Mayank SAssociate Director - Product EngineeringCommented:
Can you post the web.xml that you have created?
0
 
akp007Author Commented:
<web-app>
    <display-name>Tomcat Examples</display-name>
    <description>
      My Applications
    </description>

    <!-- Define filter mappings for the defined filters -->
    <filter-mapping>
        <filter-name>Servlet Mapped Filter</filter-name>
      <servlet-name>invoker</servlet-name>
    </filter-mapping>
    <filter-mapping>
        <filter-name>Path Mapped Filter</filter-name>
      <url-pattern>/MyApplication/servlet/*</url-pattern>
    </filter-mapping>
      
    <servlet>
        <servlet-name>HelloWWW</servlet-name>
        <servlet-class>HelloWWW</servlet-class>
    </servlet>
      
    <servlet-mapping>
        <servlet-name>HelloWWW</servlet-name>
        <url-pattern>/HelloWWW</url-pattern>
    </servlet-mapping>
</web-app>

Thank you
0
 
Mayank SAssociate Director - Product EngineeringCommented:
>> <servlet-class>HelloWWW</servlet-class>

You should specify the full-name of the servlet, along with the package.
0
 
bloodredsunCommented:
Assumming that your servlet code is in a class called HelloWWW.class which is in the directory
C:\Program Files\Apache Group\Tomcat 4.1\webapps\MyApplication\WEB-INF\classes\coreservlets
and also has the package declaration of coreservlets at the top of the code e.g.

package coreservlets;

It should be as mayankeagle says,

web.xml
-----------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app>
    <display-name>My Application</display-name>
    <description>
      My Applications
    </description>
    <servlet>
        <servlet-name>HelloWWW</servlet-name><!-- logical name for this servlet in the web.xml-->
        <servlet-class>coreservlets.HelloWWW</servlet-class><!--specify the fullname inc. package-->
    </servlet>
     
    <servlet-mapping>
        <servlet-name>HelloWWW</servlet-name><!-- logical name again from above-->
        <url-pattern>/HelloWWW.do</url-pattern><!-- the url we are mapping this servlet to-->
    </servlet-mapping>
</web-app>

and should be accessed by going to http://localhost:8080/MyApplication/HelloWWW.do

The above example is taken from a tomcat 4 webapp, you may need to alter the dtd declaration at the top if you are using tomcat 5.
0

Featured Post

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!

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