Skip to content
Advertisement

Servlet get GET and POST’s parameters at the doPost method

My problem is when I’m trying to access a POST Variable with request.getParameter("name"), it works perfectly. But in some conditions, when a POST request arrives at my application, I also need to get GET Parameter from the Query String.

As far as I can see, with getParameter, you can only access current request’s parameters, but, as in my condition, as I said, I also need to fetch GET Parameters inside doPost method.

Is there a way to fetch GET Parameters without parsing the Query String?

Advertisement

Answer

The getParameter() method can return (if possible) both GET and POST parameters as it works transparently between GET and POST. You don’t need to do any explicit work to get the GET parameters. you can use getParameter for both query parameters and POST parameters.

But should you do it? – It’s considered a poor design practice especially if there is sensitive information to be sent.

Take a look at this answer:

Advertisement