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 HTML get and post method? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "HTML get and post method?" Watch "HTML get and post method?" New topic
Author

HTML get and post method?

scott miles
Ranch Hand

Joined: Jun 16, 2011
Posts: 70

say we have html page and we are sending the values from html to server. First time we use the get method in html form.
I know that value will be passed as part of URL.But at serverside will we get it as part of HttpServletRequest and get the
passed value from HTML by request.getParameter("username");(in doget method)


If we do the above stuff with post method in HTML form .will we still get it as part of HttpServletRequestand get the
passed value from HTML by request.getParameter("username");(In dopost method)


Question2:- In case of get method values are passed as part of URL but how values get passed in case of post method?
(on some sites i have read it is passed posthttp but i did not get this meaning)


Question3:- One of my collegue asked me is there any we can only achieve with get method not with post. I am not aware of that.
Could any bodypoint me in that direction?
abhay jain
Ranch Hand

Joined: Jun 03, 2011
Posts: 130
hi ,

difference between get and post will work for you? , i mean , i think ...you want to ask that "why we use "get"/ "doget"and when we use "post"/ "dopost" "? right ?

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

scott miles wrote:.will we still get it as part of HttpServletRequestand get the
passed value from HTML by request.getParameter("username");(In dopost method)

Yes.

Question2:- In case of get method values are passed as part of URL but how values get passed in case of post method?

Encoded in the request body.

Question3:- One of my collegue asked me is there any we can only achieve with get method not with post

As a rule of thumb, GET should be used when fetching information, and POST should be used when sending data to perform an operation. Things actually go a little deeper than that, but that's a good rule-of-thumb to get started.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

And, GET and POST aren't part of HTML, they're part of HTTP.
scott miles
Ranch Hand

Joined: Jun 16, 2011
Posts: 70
Thanks Bear Bibeault for reply.

Encoded in the request body.


As per my understanding in case get method , attributes appended with URL will also be a part of request body though they wont be encoded. Does it mean that in case of post method , attributes will be passed in encoded form while in case of get method attributes wont be encoded and we can see the values in URL itself but both will be part of request body?

As a rule of thumb, GET should be used when fetching information, and POST should be used when sending data to perform an operation


Bibeault, As you mentioned GET should be used when fetching information, i think you are referring something like request.getParameter("username") kind of stuff here but as you said POST should be used when sending data to perform an operation, can you give a very small example what type of operation we are referring here ? Sorry for asking too much but did not get any concrete answer on different sites.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18643
    
    8

Small example.

"Give me the name of customer 123456" -- Get

"Set the name of customer 123456 to Freddy Gonzalez" -- Post
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

GETs have no body.

P.S. In Western cultures it is considered rude to address someone by just their last name. So it should be either Mr. Bibeault, or Bear.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HTML get and post method?