Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Differenciate GET and POST parameters

 
Thibault Delor
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65226
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Thibault Delor
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65226
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic