samedi 4 juillet 2020

how to make GET method working in servlet?

Here's my simple code which is a web form that collects some information. I'm trying to use GET method but It keeps POST method working even though I specified it on 8th line. Am I missing something?

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>My Form</title>
  </head>
  <body>
    <form action="/mSignUp" method="get">
      name: <input type="text" name="name"><br>
      hobby: sports <input type="checkbox" name="hobby" value="sports">
            cooking <input type="checkbox" name="hobby" value="cooking">
            reading <input type="checkbox" name="hobby" value="reading"><br><br>
      <input type="submit" value="submit">
    </form>

  </body>
</html>
package com;
...

@WebServlet("/mSignUp")
public class ServletEX extends HttpServlet {

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

        System.out.println(" -- doGet() -- ");
         ...

        }

    }

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

        System.out.println(" -- doPost() -- ");
        doGet(request, response);
    }
}



Aucun commentaire:

Enregistrer un commentaire