Ravi Singh
Ravi Singh

Reputation: 17

Fail to call/ map to servlet from index.html via web.xml - error - 404

    I am creating a simple servlet on spring tool set / eclips but am failing to run it. on running 
    the project, i am able to see my index home page html and click on the link for my jsp but fail
    to get to the servlet link. i have attached the web.xml file which has the paths. i am 
    confused 

              1. what should i put  in servlet-name 
              2. what should i put  in servlet-class  
              3. what should i put  in url-patter 
              4. Is there is any relation between the index.html file and web.xml file.
              5. Finally what is my servlet-class supposed to hold?

My index.html holds: ====================

<ul>
          <li>To a <a href="HellBoy.jsp">JSP page</a>.
          <li>To a <a href="/HellBoy">HelloWorldServlet</a>.
      </ul>

My web.xml holds: =================

  <servlet>  
    <servlet-name>HellBoyServlet</servlet-name>
    <servlet-class>com.ravi.servlet.HellBoy</servlet-class>
 </servlet>


<servlet-mapping>
    <servlet-name>HellBoServlet</servlet-name>
    <url-pattern>/Hell</url-pattern>
</servlet-mapping>
    -----------------------------------------

Upvotes: 0

Views: 768

Answers (3)

Aniket Kulkarni
Aniket Kulkarni

Reputation: 12983

index.html

  • Do not write /HellBoy in href attribute.
  • Here give name that matches <url-pattern>, in this case it it Hell.
  • Do not need to change web.xml.

Change to

<li>To a <a href="Hell">HelloWorldServlet</a>

what should i put in servlet-name

<servlet-name> must match both in <servlet> and <servlet-mapping>.

what should i put in servlet-class

Fully qualified name of servlet

what should i put in url-patter

URL pattern that you wish.

For all questions, please read carefully The Java EE 6 Tutorial Chapter 15 Java Servlet Technology

Upvotes: 0

Mitul Maheshwari
Mitul Maheshwari

Reputation: 2647

You will have to make entry in web.xml like this

      <servlet>
        <description> desc</description>
        <display-name>HelloBoy</display-name>
        <servlet-name>HelloBoy</servlet-name>
        <servlet-class>com.abc.xyz.HelloBoy</servlet-class>
      </servlet>
      <servlet-mapping>
        <servlet-name>HelloBoy</servlet-name>
        <url-pattern>/HelloBoy</url-pattern>
      </servlet-mapping>

and if you use eclipse for your IDE then directly create new servlet, it will automatically make all entry in web.xml

Upvotes: 1

tom87416
tom87416

Reputation: 542

The URL of the servlet should be http://{host}/{appname}/Hell.

if you want to link your servlet access from /HellBoy http://{host}/{appname}/HellBoy, you should

<servlet-mapping>
    <servlet-name>HellBoServlet</servlet-name>
    <url-pattern>/HellBoy</url-pattern>
</servlet-mapping>

Upvotes: 0

Related Questions