I am required to do some small tasks with JSP; being very new to JSP I was wondering if there was any possibility to get only GET or only POST parameters from the HTTP request.
I have seen ServletRequest.getParameter (and alikes) but it seems that those methods get both GET and POST parameters. Is there a way to get only one of them, without parsing the URL or the request body myself? And if not, is there any precedence rule which values overwrite which (like POST parameters always overwriting GET parameters)?
Generally, requests should better be handled in servlets. They have doGet(request, response)
and doPost(request, response)
methods, to differentiate the two.
If you really insist on doing it in a JSP, you can differentiate the methods using request.getMethod()
. It would return GET
or POST
.
Since this is homework, I guess the point is to learn how to use servlets and their doX
methods, so do it that way.
Update: You can get the query string (request.getQueryString()
), which is only the get parameters, and parse it, but I wouldn't say that's a common and good practice.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With