Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Not able to run my first Servlet..... 404 error!!!

807601Feb 7 2008 — edited Feb 8 2008
Hi,
I am new to Java.
I am trying to create a small servlet application. I am using Tomcat 5.5 server and eclipse for this.
I have first writtern a HTML form which on submission is redirected to a servlet that displays the information submitted. but i am not able to evn open the html file through browser, i am getting 404 error.
My html codes and Servlet codes are inside the htmlform package...
When i type http://localhost:8080/htmlform/form.html i am gettig 404 error... Also let me know if any thing is wrong with the codes...

Here is my code...
form.html

<html>
<head>
<title> This is a HTML page </title>
</head>
<body>
<p><h3>This page displays a submission form</h3></p>
<form method="GET" action="/htmlform/LoginServlet">
<p> USERNAME: <input type="text" name="username"/> </p>
<p> PASSWORD: <input type="password" name="password" /> </p>
<p> <input type="submit" value="Press Me" name="submit"/> </p>
</form>
</body>
</html>


LoginServlet.java

package htmlform;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class LoginServlet extends HttpServlet{
/**
*
*/
private static final long serialVersionUID = 1L;

public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String username = request.getParameter("username");
String password = request.getParameter("password");
pw.println("<html><head><title>This is the out put page</title></head");
pw.println("<body><h2>If you can see this page then your form is cleanly processed</h2><br>");
pw.println("<h2>Congratulations!!!</h2>");
pw.println("<p>Your user name is: "+ username+ "</p>");
pw.println("<p>Your password is: "+ password + "</p>");
pw.println("<br></body></html>");
}
}

web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!--<!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>
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
</web-app>


Thanks in advance
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 7 2008
Added on Feb 7 2008
2 comments
508 views