getting error HTTP Status 405 - HTTP method GET is not supported by this URL but not used `get` ever?

后端 未结 3 2051
青春惊慌失措
青春惊慌失措 2020-12-17 22:59

I\'m a beginner and making a small registration program with database But i\'m trying to run this but it\'s giving me some errors pls help:

HTTP Status 405 -         


        
相关标签:
3条回答
  • 2020-12-17 23:38

    I think your issue may be in the url pattern. Changing

    <servlet-mapping>
        <servlet-name>Register</servlet-name>
        <url-pattern>/Register</url-pattern>
    </servlet-mapping>
    

    and

    <form action="/Register" method="post">
    

    may fix your problem

    0 讨论(0)
  • 2020-12-17 23:41

    The problem is that you mapped your servlet to /register.html and it expects POST method, because you implemented only doPost() method. So when you open register.html page, it will not open html page with the form but servlet that handles the form data.

    Alternatively when you submit POST form to non-existing URL, web container will display 405 error (method not allowed) instead of 404 (not found).

    To fix:

    <servlet-mapping>
        <servlet-name>Register</servlet-name>
        <url-pattern>/Register</url-pattern>
    </servlet-mapping>
    
    0 讨论(0)
  • 2020-12-17 23:56

    Override service method like this:

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

    And Voila!

    0 讨论(0)
提交回复
热议问题