Tomcat servlet HTTP Status 405? Method Not Allowed

protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=gb2312");
        PrintWriter out = resp.getWriter();
        out.println("<html><head><title>");
        out.println("");
        out.println("</title></head><body>");
        String name = req.getParameter("username");
        String pwd = req.getParameter("password");
        if("1234".equals(name) && "1234".equals(pwd)) {
            ServletContext context = getServletContext();
            RequestDispatcher rd = context.getRequestDispatcher("/welcome");
            rd.forward(req, resp);
        } else {
            RequestDispatcher rd = req.getRequestDispatcher("login2");
            rd.include(req, resp);
        }
        out.println("</body></html>");
        out.close();
    }
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp); 
    }

has overridden the doGet and doPost methods, and the form is a post submission

@Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("text/html;charset=gb2312");
        PrintWriter out = resp.getWriter();
        out.println("<form method=post action=portal>");
        out.println("<table>");
        out.println("<tr>");
        out.println("<td></td>");
        out.println("<td><input type=text name=username></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td></td>");
        out.println("<td><input type=password name=password></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td><input type=reset value=></td>");
        out.println("<td><input type=submit value=></td>");
        out.println("</tr>");
        out.println("</table>");
        out.println("</form>");    
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }

the following is the information displayed on the browser after submitting the form:

Feb.28,2021

< form method=post action=portal >

so
clipboard.png

the login above should be the portal of the corresponding action.

compare whether there is a problem with the annotation path of the configuration.

Menu