HTTP状态404 - / Registration / servlet / Register

时间:2014-12-22 17:39:30

标签: servlets http-status-code-404

我的计划 (web.xml)中 **

<?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>Registration</display-name>

  <servlet>
        <servlet-name>Register</servlet-name>
        <servlet-class>Register</servlet-class>
  </servlet>

  <servlet-mapping>
        <servlet-name>Register</servlet-name>
        <url-pattern>/Register</url-pattern> 
  </servlet-mapping>

</web-app>

**

现在的servlet程序(Register.java)

**

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;

    /**
     * Default constructor. 
     */
    public Register() {
        // TODO Auto-generated constructor stub
    }

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
    }

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


        response.setContentType("text/html");
        PrintWriter pw=response.getWriter();

        String n=request.getParameter("uname");
        String p=request.getParameter("upassword");
        String e=request.getParameter("uemail");
        String c=request.getParameter("ucountry");

        try
        {
            Class.forName("");
            Connection con=DriverManager.getConnection("");
            PreparedStatement psmt=con.prepareStatement("insert into nv_employee values(?,?,?,?)");

            psmt.setString(1, n);
            psmt.setString(2, p);
            psmt.setString(3, e);
            psmt.setString(4, c);



            int i=psmt.executeUpdate();

            if(i>0)
            {
                pw.println(n);
                pw.println(p);
                pw.println(e);
                pw.println(c);
                pw.println("Registered Successfully");
            }

        }

        catch(Exception ex)
        {
            System.out.println(ex);
        }

        pw.close();
        // TODO Auto-generated method stub
    }

}

**

html page

register.html

**

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="/Register" method="post">

Name: <input type="text" name="uname"><br>
Password: <input type="password" name="upassword"><br>
Email:<input type="text" name="uemail"><br>
Country: <select name="ucountry">
<option>India</option>
<option>Pakistan</option>
<option>USA</option>
</select><br>


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

**

这是我的代码..运行后我得到HTTP状态404 - /Registration/servlet/Register...kindly帮我知道我错在哪里?

0 个答案:

没有答案