Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Iarla O'Riada
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
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • 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.
 
Laurentiu Doe
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)
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
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.
 
Nivedita Gautam
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!
 
Sujoy Mukherjee
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!