0

Basically I am trying to map a servlet to my web.xml but it's not working.

Here is how i am doing it:

Project directory: C:\Program Files (x86)\Apache Software Foundation\Tomcat 9.0\webapps\ROOT

FYI: I have removed all apache default webapp files and have putted my own project, so it could be accessed with just localhost which works fine.

My servlet location in my drive: C:\Program Files (x86)\Apache Software Foundation\Tomcat 9.0\webapps\ROOT\src\duck\reg\pack\userlogin.java

My package in eclipse IDE: package in eclipse IDE Image

and my web.xml file:

 <?xml version="1.0" encoding="UTF-8"?>
 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
   <display-name>ROOT</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>

   <servlet>
     <servlet-name>userlogin</servlet-name>
     <servlet-class>duck.reg.pack.userlogin</servlet-class>
   </servlet>
   <servlet-mapping>
     <servlet-name>userlogin</servlet-name>
     <url-pattern>/ROOT/WebContent/src</url-pattern>
   </servlet-mapping>
</web-app>

My HTML Form:

<form method="POST" action="/ROOT/WebContent/src" autocomplete="off">
    .../ code
</form>

I don't know why but this doesn't works, and I am not running apache through Ecplise

Thanks for all replies:)

Denmaq
  • 1
  • 2

1 Answers1

0

Change your web.xml as below

<servlet-mapping>
     <servlet-name>userlogin</servlet-name>
     <url-pattern>*.do</url-pattern>
 </servlet-mapping>

and In your HTML form

<form method="POST" action="userlogin.do" autocomplete="off">
    .../ code
</form>

For complete explanation refer the page taken from the book Head First Servlets & JSP.

enter image description here

Sundararaj Govindasamy
  • 8,180
  • 5
  • 44
  • 77
  • 1
    Your project is a Java project, not a web (servlet) project, Create dynamic web project in eclipse as described here. you MUST follow the directory structure for Web Projects, otherwise Tomcat cannot find your servlet. http://www.srccodes.com/p/article/3/Tomcat-Hello-World-Servlet-using-Eclipse-IDE and this link http://www.javatpoint.com/creating-servlet-in-eclipse-ide – Sundararaj Govindasamy Sep 27 '16 at 19:46