• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

Is http GET the default method for web browsers contacting web servers?  RSS feed

 
Ranch Hand
Posts: 87
Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am running a test servlet on Tomcat and have implemented different behaviours for the doPost and doGet methods. When I access from the browser, only the doGet method gets called ultimately.

The Firefox developer tools show me a GET request from the browser to my Tomcat instance. Do browsers ever call the POST http method? How could I make this happen?

Thank you
 
Rancher
Posts: 42974
76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use POST from within an HTML form via the method attribute.
 
Iarla O'Riada
Ranch Hand
Posts: 87
Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ulf Dittmer. So clicking a standard <a href.. or entering a URL in the address bar uses GET and POST needs to be implemented though some other explicit functionality.
 
Greenhorn
Posts: 3
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, the default operation is a GET.

To do a POST you need something like:
<form action="yourControllerUrl.do" method="POST">
<input type="text" name="age">
<input type="submit" value="Submit">
</form>

You can also use something like Fiddler if you do not want to make the requests from browser. (sometimes it's simpler to test)
 
Sheriff
Posts: 67257
170
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Iarla O'Riada wrote:Thanks Ulf Dittmer. So clicking a standard <a href.. or entering a URL in the address bar uses GET and POST needs to be implemented though some other explicit functionality.



Yes, links and address bar requests will be GETs. A POST can be submitted via a form (as already show), and any HTTP method can be submitted via Ajax.
 
Greenhorn
Posts: 3
C++ Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For calling doGet method:

<form action="SomeServlet" method="get">

</form>

For calling doPost method:

<form action="SomeServlet" method="post">

</form>

When no form method id specified, service method is called if it exists!
 
Ranch Hand
Posts: 51
Netbeans IDE Oracle Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Nivedita Gautam wrote:For calling doGet method:

<form action="SomeServlet" method="get">

</form>

For calling doPost method:

<form action="SomeServlet" method="post">

</form>

When no form method id specified, service method is called if it exists!



Hi Nivedita, I beg to differ at your last statement.
When no form method is specified, by default Get is called(as it is already mentioned also in previous posts.
 
expectation is the root of all heartache - shakespeare. tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!