Reputation: 243
I am a newbie to servlets. I created a dynamic web project in eclipse. I have following files in my project
home.html validateServlet.java
I have defined validated servlet as an action in home.html form. However when I run it, I get http status 404. Below is the hierarchy of my project
Project
Java Resources
src
com.servlets
ValidateServlet.java
build
WebContent
META-INF
WEB-INF
web.xml
hello.html
Contents of my web.xml are as follows:
<?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" xmlns:web="http://java.sun.com/xml/ns/javaee/web- app_2_5.xsd" 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>Website</display-name>
<servlet>
<description></description>
<display-name>ValidateServlet</display-name>
<servlet-name>validate</servlet-name>
<servlet-class>com.oracle.coen235.servlets.ValidateServlet</servlet-class>
</servlet>
</web-app>
In my hello.html, action is specified as ,
What might be the issue? I guess I am not able to generate the class file for my servlet. Can anyone guide me through this problem?
Upvotes: 0
Views: 57
Reputation: 12538
You seem to mix things up.
<servlet-class>com.oracle.coen235.servlets.Validate</servlet-class>
Should list the full class name. I don't see your package name.
It should be
<servlet-class>com.oracle.coen235.servlets.ValidateServlet</servlet-class>
or whatever your package name is.
We are you mapping your servlet to a path? It should be something like:
<servlet-mapping>
<servlet-name>validate</servlet-name>
<url-pattern>/validate</url-pattern>
</servlet-mapping>
or an annotation directly in your servlet class.
Upvotes: 1