HTTP method POST is not supported by this URL error message

formgetpostservletlogin()dopostdogetformhiddenmethod=login,405method not allowed"HTTP method POST is not supported by this URL" 
<form class="form-horizontal" method="post" action="${pageContext.request.contextPath }/user">
                        
                        <input type="hidden" name="method" value="login">
                        
                        <div class="form-group">
                            <label for="username" class="col-sm-2 control-label"></label>
                            <div class="col-sm-6">
                                <input type="text" class="form-control" id="username" name="username"
                                    placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="inputPassword3" class="col-sm-2 control-label"></label>
                            <div class="col-sm-6"> 
                                <input type="password" class="form-control" id="inputPassword3" name="password"
                                    placeholder="">
                            </div>
                        </div>

form code of jsp

Apr.09,2021

although you are right. But HTTP is designed to support only these methods. If you want to use custom logic to deal with it, you must first use the servlet method to get the post data and forward it to the custom processing module.


you confuse servlet's method with HTML form's method (that is, HTTP method)). They are not directly related.
and the method property value of HTML form can only be get or post.

< hr >

to implement a custom HTTP method "LOGIN", you need to add logic to servlet that handles HTTP LOGIN method, such as

//  HttpServlet.service()  HTTP method
package demo;

import javax.servlet.http.HttpServlet;

class CustomHttpServlet extends HttpServlet {
    protected void service(HttpServletRequest req, HttpServletResponse resp) {
        if (req.getMethod().toLowerCase() == "login") {
            this.doLogin(req, res);
            return;
        }
        super.service(req, resp);
    }

    protected void doLogin(HttpServletRequest req, HttpServletResponse resp) {
        //  doGet() 
    }
}

you cannot use HTML form testing at this time. You should use the interface testing tool to send a request similar to the following

LOGIN  http://127.0.0.1:8080/xxx

for example

curl -X LOGIN  http://127.0.0.1:8080/xxx
Menu