File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Differenciate GET and POST parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Differenciate GET and POST parameters" Watch "Differenciate GET and POST parameters" New topic
Author

Differenciate GET and POST parameters

Thibault Delor
Greenhorn

Joined: Nov 06, 2009
Posts: 7
Hello,
Take a look at this form :

If I print all parameter with a servlet like this :

i'll have this result :

What i want to show is that the request object got all parameters, those send in the url and those send in the request body thanks to the POST method.
Is there a way to get only parameters send in the body request only??
For exemple in PHP you can get $_GET and $_POST, is there an equivalent in java?

Thanks!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61773
    
  67

No.

And mixing parameters on the query string (it's still not a "get") with those in the request body is considered very bad form. For a POST, the params should be in the body and there shouldn't be any on the query string.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Thibault Delor
Greenhorn

Joined: Nov 06, 2009
Posts: 7
Hum ok, i don't understand why it's a bad practice.

Imagine i'm consulting a client at the url client?id=3. In this page i have a form to modify the client informations. This form action is still client?id=3.
In my servlet, in the doPost i perform all action needed to update the client, in the doGet i forward to the jsp which present all information of the client. And the end of my doPost I call doGet to avoid duplicate code.
In my form, i could put the id into an input hidden, but since my url to consult my client is client?id=3, i don't feel that logical.
Here my example is not totally pertinent because i need the client ID in my doPost but imagine a parameter in the query string that is not needed in the doPost and really needed in the doPost, for exemple a page number.

I really don't understand why it would be a bad idea to mix parameters, i really need that the client (the browser) return at the exactly same url after the doPost...

PS: I'm not a Java expert and i don't try to prove something, i don't have the knowledge for that, i just try to understand
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61773
    
  67

It's not a Java thing, it's an HTTP thing. In a POST the params should be in the body.

In any case, the only way you'll be able to differentiate is to grab the query string to see what's ben specified there.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Differenciate GET and POST parameters