开发者

JSP, GET and POST parameters

开发者 https://www.devze.com 2023-01-25 05:06 出处:网络
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 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 pre开发者_开发技巧cedence 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.


In JSP, you can look at the request object to determine what kind of request it was (GET or POST), but there's only one parameter map.


Try [Servlet + JSP]. At Servlet you can choose between doPost() or doGet()

0

精彩评论

暂无评论...
验证码 换一张
取 消