• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTTP Status 404 ERROR

 
ayesha tahseen
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am trying to develop a web application. But I am getting the following error:

HTTP Status 404 ERROR

Register.java

package com.csc.newapp.org;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class Register
*/
@WebServlet("/Register")
public class Register extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html");
PrintWriter out=response.getWriter();

String t_name=request.getParameter("NAME");
String t_email=request.getParameter("EMAIL_ID");
String t_phNo=request.getParameter("PHONE_NUMBER");
String t_companyName=request.getParameter("COMPANY_NAME");
String t_passsword=request.getParameter("PASSWORD");
String t_gender=request.getParameter("GENDER");
String t_dob=request.getParameter("DOB");
String t_rideType=request.getParameter("RIDETYPE");
String t_ofcAddr=request.getParameter("OFFICE_ADDRESS");
String t_homeAddr=request.getParameter("HOME_ADDRESS");
String t_userName=request.getParameter("USER_NAME");

try {
String url="jdbc:mysql://localhost:3306/NEWAPP";
String username="root";
String password="root";

Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection(url,username,password);
System.out.println("Connection establishing...");

PreparedStatement ps=conn.prepareStatement("INSERT INTO REGISTRATION VALUES(?,?,?,?,?,?,?,?,?,?,?)");
ps.setString(1, t_name);
ps.setString(2, t_email);
ps.setString(3, t_phNo);
ps.setString(4, t_companyName);
ps.setString(5, t_passsword);
ps.setString(6, t_gender);
ps.setString(7, t_dob);
ps.setString(8, t_rideType);
ps.setString(9, t_ofcAddr);
ps.setString(10, t_homeAddr);
ps.setString(11, t_userName);
int i=ps.executeUpdate();
if(i>0)
{
out.println("You are successfully registered");
}

} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}

}


registration.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Register Yourself Here</title>
</head>
<body>
<form action="register">
<table>
<tr>
<td> Name </td>
<td> <input type="text" name="name"></td>
</tr>

<tr>
<td> Email Id</td>
<td> <input type="text" name="email"></td>
</tr>

<tr>
<td>Mobile Number</td>
<td> <input type="text" name="mobile"></td>
</tr>

<tr>
<td>Company Name</td>
<td><input type="text" name="companyName"></td>
</tr>

<tr>
<td> Password </td>
<td><input type="password" name="userName"></td>
</tr>

<tr>
<td>Gender</td>
<td> <input type="radio" name="gender" value="Male">Male</td>
<td><input type="radio" name="gender" value="Female">Female</td>
</tr>

<tr>
<td> Date Of Birth</td>
<td> <input type="text" name="dob"></td>
</tr>

<tr>
<td>Ride Type</td>
<td> <select >
<option value="Rider">Rider</option>
<option value="Seeker">Seeker</option>
<option value="Both">Both</option>
</select></td>
</tr>

<tr>
<td>Office Address</td>
<!-- <td> <input type="text" name="ofcAddr"></td> -->
<td><textarea rows="4" cols="20">Enter address1...</textarea></td>
</tr>

<tr>
<td>Home Address</td>
<!-- <td> <input type="text" name="homeAddr"></td> -->
<td><textarea rows="4" cols="20">Enter address2...</textarea></td>
</tr>

<tr>
<td>User Name</td>
<td> <input type="text" name="name"></td>
</tr>

</table>
<input type="submit" value="register" />
</form>
</body>
</html>

web.xml

<?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>NewApp</display-name>
<servlet>
<servlet-name>registration</servlet-name>
<servlet-class>Register</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>registration</servlet-name>
<url-pattern>/Register.do</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>registration.jsp</welcome-file>
</welcome-file-list>
</web-app>


Regards,
Ayesha Tahseen
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


ALL classes used in servlets Must be in a named package and the class files stored in a location which reflects that name.

When the JVM tries to load a class with only the "default" package, it looks in the "current" directory - something you have no control over.

This is a very common error - the container can't load your class and you get a 404

Bill
 
ayesha tahseen
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the help William

I changed my xml file as

<servlet-name>registration</servlet-name>
<servlet-class>com.csc.newapp.org.Register</servlet-class>

But still the same error
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
404 means the servlet container is not finding your servlet program.

The compiled class files must be in a directory based on the package name.

If you will search this forum for "404" you will find MANY discussions of this problem.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also covered in the ServletsFaq
 
ayesha tahseen
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You
My error resolved
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic