Error 405 HTTP method POST is not supported by this URL

1

I'm doing a web application (JSP) with eclipse with the google app engine plugin and it throws me an error when I press the send button:

  

"Error 405 HTTP method POST is not supported by this URL"

I've tried with "get" and if it works, but in this case I'm interested in doing it with post. Any solution?

JSP Code:                                          Hello App Engine        

   <body>   
       <form action="/hello" method="post">
           <input type="text" name="name"/>
           <input type="submit" value="Enviar">
       </form>
   </body>
</html>

Servlet Code

public class HelloAppEngine extends HttpServlet {

@Override
public void doGet(HttpServletRequest request, HttpServletResponse     response) 
  throws IOException {

response.setContentType("text/plain");
response.setCharacterEncoding("UTF-8");

String name = request.getParameter("name");
response.getWriter().print("hola " + name + "\r\n");
    
asked by Elenasys 02.02.2018 в 19:34
source

1 answer

3

Try overwriting the method doPost to be able to receive request of type post:

public class HelloAppEngine extends HttpServlet {

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

    response.setContentType("text/plain");
    response.setCharacterEncoding("UTF-8");

    String name = request.getParameter("name");
    response.getWriter().print("hola " + name + "\r\n");

}

    //....
    
answered by 02.02.2018 / 19:47
source