此URL不支持HTTP方法GET

时间:2014-10-03 06:04:12

标签: java html servlets

   <form method="post"    action="RegisterServletPath">

    Name:<input type="text" name="userName"><br>
    Password:<input type="password" name="password"><br>
    Email Id:<input type="text" name="email"><br>
    Language: <select name="language">
        <option>Hindi</option>
        <option>English</option>
        <option>French</option>
    </select> <br>
    <input type="submit" value="Submit">

  </form>

提交表单后发生以下错误 HTTP状态405 - 此URL不支持HTTP方法GET 这是我的java类。我只用html格式定义了post方法和post方法

   public class RegisterServlet extends HttpServlet {

       private static final long serialVersionUID = 1L;

       public void doPost(HttpServletRequest request, HttpServletResponse response)
           throws ServletException, IOException {

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

            String n = request.getParameter("userName");
            String p = request.getParameter("password");
            String e = request.getParameter("email");
            String c = request.getParameter("language");

            try {

                Class.forName("net.ucanaccess.jdbc.UcanaccessDriver");

                Connection con =     DriverManager.getConnection("jdbc:ucanaccess://D:/eclipse/register.accdb","","");

                PreparedStatement ps = con.prepareStatement("insert into USERDETAILS values(?,?,?,?)");

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

                int i= ps.executeUpdate();
                if (i > 0) {
                     out.print("You are successfully registered...");   
                }
            }
            //... not relevant here
        }
    }

web.xml 


<display-name>SimpleServletProject</display-name>   
<servlet>
<servlet-name>RegisterServlet</servlet-name>
<servlet-class>org.venkatesh.Servlet.RegisterServlet</servlet-class> 
</servlet>

<servlet-mapping>
<servlet-name>RegisterServlet</servlet-name>
<url-pattern>/RegisterServletPath</url-pattern>
</servlet-mapping>

1 个答案:

答案 0 :(得分:-1)

添加其余的servlet代码,我认为你要么使用doGet方法并从中调用super.doGet,要么不使用doGet但不幸的是doGet方法正在调用HttpServlet

这是另一个问题!从哪里调用doGet方法?

如果找不到,请尝试添加

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    doPost(request, response);
}

这应该解决问题,如果它没有让我知道我的所有假设是否错误。