0
<form method="post" action="">
    <input type=text name="nm" />
</form>

request.getParameter("nm");

I can get the parameter named nm, but I can't confirm it's confirm method ,post or get??

3 Answers3

0

request.getMethod() returns the web method used (post, get etc...)

Totò
  • 1,694
  • 12
  • 17
0

From JavaEE 6 docs HttpServletRequest#getMethod()

Returns the name of the HTTP method with which this request was made, for example, GET, POST, or PUT. Same as the value of the CGI variable REQUEST_METHOD.

Aniket Kulkarni
  • 12,142
  • 9
  • 65
  • 83
0

By default if you dont specify anything in your form ,

<form action="">
   <input type=text name="nm" />
</form>

it will be get . (i.e) you need to override doGet . ti know the method used , you can achieve it through request.getMethod() which returns a String specifying the name of the method with which this request was made . see this to understand the difference What is the difference between POST and GET? and use the appropriate one.

Hope this helps !!

Community
  • 1
  • 1
Santhosh
  • 8,045
  • 2
  • 26
  • 54