1

request.getParameter() to retrieve items sent by POST and/or GET.

String name = request.getParameter("name");

But how can we distinguish between these two cases? In fact, if I send both a post and get with the same name, what getParameter returns me?

lopez.mikhael
  • 9,943
  • 19
  • 67
  • 110

3 Answers3

4

An HTTP request can only have one method associated. So in your case, your request is either a GET request or a POST request, but not both. Note that other HTTP methods than GET or POST exists (OPTIONS, PUT, DELETE, ...).

If you want to know which method was used in your current request, you can use request.getMethod().

Guillaume Darmont
  • 5,002
  • 1
  • 23
  • 35
0

request.getParameter("name"); will return the value associated with HTML/JSP element having id="name"in both GET and POST cases. If you want to check whether the request was GET or POST you can use request.getMethod();

Rohan
  • 3,068
  • 1
  • 20
  • 26
0

You can use only one at a time GET or POST. And your statement retrieve value whose name/id="name". You can check method by request.getMethod(); Also GET is used for limited data around 2 kb and POST for unlimited data to be retrieved.