3

The xml file is located in WebContent/WEB-INF/web.xml of my project. I am using Eclipse and running Tomcat (which is not installed via Eclipse. I prefer it to be a separate installation).

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>EmployeeManagement</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <context-param>
    <param-name>name</param-name>
    <param-value>Pramod</param-value>
  </context-param>
  <servlet-mapping>
        <servlet-name>Registration</servlet-name>
        <url-pattern>/EmployeeManagement/WebContent/Registration</url-pattern>
   </servlet-mapping>
</web-app>

It doesnt work when the form page submits to the servlet. I am getting a 404 error everytime. I have been encountering this problem for a while. Somebody please help me.

Prasad Kharkar
  • 13,410
  • 5
  • 37
  • 56
Pramod
  • 271
  • 2
  • 3
  • 5

6 Answers6

9

You are missing <servlet>...</servlet> tag which is important to mapping. So use following :

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>EmployeeManagement</display-name>
<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<context-param>
    <param-name>name</param-name>
    <param-value>Pramod</param-value>
</context-param>
<servlet>
    <servlet-name>Registration</servlet-name>
    <servlet-class>com.yourPackageName.yourServletName</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Registration</servlet-name>
    <url-pattern>/EmployeeManagement/WebContent/Registration</url-pattern>
</servlet-mapping>
</web-app>

and you should give action value on your form like following:

<form action="/EmployeeManagement/WebContent/Registration" method="post">

      //Some code here

</form> 

and also note it down all values are case sensitive on the following code:

<servlet>
    <servlet-name>Registration</servlet-name>
    <servlet-class>com.yourPackageName.yourServletName</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Registration</servlet-name>
    <url-pattern>/EmployeeManagement/WebContent/Registration</url-pattern>
</servlet-mapping>

Your servlet name Registration should be same on both tags <servlet>...</servlet> and <servlet-mapping>...</servlet-mapping> and also package name should be same where your servlet class is located.

Yubaraj
  • 3,800
  • 7
  • 39
  • 57
2

you have not mapped servlet name to servlet class, It should be like given below,

In <servlet-class> give the path of your servlet

    <servlet>
         <servlet-name>Registration</servlet-name>
         <servlet-class>com.Registration<servlet-class>
    </servlet>
    <servlet-mapping>
         <servlet-name>Registration</servlet-name>
         <url-pattern>/EmployeeManagement/WebContent/Registration</url-pattern>
    </servlet-mapping>
upog
  • 4,965
  • 8
  • 42
  • 81
0

Check your form action. Is the path there

/EmployeeManagement/WebContent/Registration

or

YOURAPPCONTEXT/EmployeeManagement/WebContent/Registration

or

YOURAPPNAME/EmployeeManagement/WebContent/Registration
Mite Mitreski
  • 3,596
  • 3
  • 29
  • 39
0

You forgot a vital part of the configuration. You should add this to your web.xml before servlet-mapping tag:

<servlet>
    <servlet-name>Registration</servlet-name>
    <servlet-class>com.name.of.your.servlet.class</servlet-class>
</servlet>
M. Abbas
  • 6,409
  • 4
  • 33
  • 46
0

You have specifyed a servlet-mapping and used the name Registration in servlet-name without defining it before.

You need to define the servlet before using it in a servlet mapping

<servlet>
    <servlet-name>Registration</servlet-name>
    <servlet-class>[fully qualifyied name of your servlet]</servlet-class>
</servlet>
A4L
  • 17,353
  • 6
  • 49
  • 70
0

You are missing another part to define the servlet in the web.xml

<servlet>
   <servlet-name>Registration</servlet-name>
   <servlet-class>
      package.path.to.RegistrationServlet
  </servlet-class>
</servlet>
D_G
  • 1