• 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

how do i choose doget() or dopost() corrently?

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i know the different between the post and get,but ,you know ,when request is maked by container,the container will automatically choose the right http method (post or get),and then it will past this http method (post or get) to servlet,and then ,the servlet will figure it out.


but the question is ,the servlet is designed by us,and how do we make the right choose between dopost() or doget()?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hk mingham wrote:but the question is ,the servlet is designed by us,and how do we make the right choose between dopost() or doget()?


Case counts. Precision counts. It's doGet() and doPost().

What do you mean by "how we choose?"

Do you mean how do we choose which gets called? You don't. The container calls the one that matches the HTTP method of the request.

Do you mean how do we choose which to implement? You implement whichever one you want to support. doGet() for GETs. doPost() for POSTs. Both if you want to support both.
 
Ranch Hand
Posts: 155
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hk mingham wrote:
the container will automatically choose the right http method


Yeah, that depends on the request.
The container calls the service() method. And then depending on the type of the request, service() method calls either doGet() or doPost().
You can override the service() method if you want, but it's not advisable.

Hk mingham wrote:
how do we make the right choose between dopost() or doget()?



In case you don't not the type of service and want to process both GET and POST requests in the same way, then you can write the functionality in one method and call that method from the other.

Example:


BUt it's better not to mix GET and POST - as they're made for different purposes.
GET is used to get data, it's not supposed to change anything on the server.
POST is not idempotent, data submitted in the body of POST is usually used to change something on server. For example, a transaction.
 
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

Trivikram Kamat wrote:BUt it's better not to mix GET and POST - as they're made for different purposes.


This is an important point that many people do not properly understand. It's more important in web services than in web applications, but it's still an important distinction.
 
Hk mingham
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
totally thank you Trivikram Kamat and Bear Bibeault,i have a clearier mind on it after i have finished the answer from you.yeah,thaks so much.
 
Trivikram Kamat
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome
 
Wanna see my flashlight? How about this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic