此 URL 不支持 HTTP 方法 POST



有人可以告诉我为什么我会收到此错误吗,我已经在网上进行了无休止的搜索并尝试了各种建议,但似乎没有任何效果。错误:- 此 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);
    }
  }
}
}

不要更改可见性修饰符

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

考虑更改为

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

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

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

公共和受保护之间的区别:

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

相关内容

最新更新