2014-10-03 93 views
2
<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後的形式支持。我只定義了POST方法,並呼籲POST方法在HTML表單HTTP GET方法不受此URL

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> 
+0

控件是否已經到達RegisterServlet?嘗試添加一些打印語句來確認。 – RandomQuestion 2014-10-03 06:07:36

+0

是控制器無法達到RegisterServlet @Jitendra – john 2014-10-03 06:14:29

+0

那麼請向我們展示您的web.xml配置,您將URL映射到控制器。 – Daniel 2014-10-03 06:33:45

回答

-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); 
} 

這應該解決的問題,如果它不那麼讓我知道如果我所有的假設是錯誤的。

+0

所以如果這解決了您的問題,那麼將其標記爲解決方案, – 2014-10-03 09:08:01

相關問題