此URL不支持HTTP方法POST

时间:2014-02-19 01:43:53

标签: servlets

有人可以告诉我为什么我会收到这个错误,我在网上做了无数的搜索,尝试了各种各样的建议似乎没有用。 错误: - 此URL不支持HTTP方法POST

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

@SuppressWarnings("static-access")
public void doPost(HttpServletRequest request, HttpServletResponse response) 
        throws ServletException, IOException {

    DbConnection dbConn = null;
    Connection conn = null; 
    CallableStatement proc = null;
    response.setContentType("text/html");
    PrintWriter out = response.getWriter();

    // get the variables entered in the form
    String clientID = request.getParameter("cid");
    String loginID = request.getParameter("lid");
    String password = request.getParameter("pwd");
    String instName = request.getParameter("iName");
try{    
    dbConn = new DbConnection();
    conn = dbConn.connection();
    proc = conn.prepareCall("{call pa_internal_admin.fu_login(?,?,?,?)}");
    proc.setString(1, clientID);
    proc.setString(2, loginID);
    proc.setString(3, password);
    proc.setString(4, instName);
    proc.execute();
    response.sendRedirect("adminHome.jsp");
    proc.close();

} catch (SQLException e) {
    out.println("SQLException caught: " + e.getMessage());      
} catch (Exception e) {
    out.println(e);
} finally {
    // Always close the database connection.
    try {
        if (conn != null)
            conn.close();
    } catch (SQLException ignored) {
        out.println(ignored);
    }
  }
}
}

2 个答案:

答案 0 :(得分:0)

不要更改可见性修饰符

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

考虑改为

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

答案 1 :(得分:0)

你在post方法中犯了一些错误,就像你输入public一样。但是,你应该改变protected。首先,您必须在发布问题之前预览代码。

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
    {
    DbConnection dbConn = null;

公众与受保护者之间的区别:

Modifier    | Class | Package | Subclass | World
————————————+———————+—————————+——————————+———————
public      |  ✔    |    ✔    |    ✔     |   ✔
————————————+———————+—————————+——————————+———————
protected   |  ✔    |    ✔    |    ✔     |   ✘