• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Differenciate GET and POST parameters

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
An elephant? An actual elephant. Into the apartment. How is the floor still here. Hold this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic