Forums Register Login

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

+Pie Number of slices to send: Send
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()?
1
+Pie Number of slices to send: Send
 

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.
1
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
 

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.
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
You're welcome
Whoever got anywhere by being normal? Just ask this exceptional tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1492 times.
Similar Threads
HFS&J Question on page 118
doubts on service, post, get metods?
Servlet Objects
doPost and doGet
doGet(req,res) within doPost()
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 01:12:48.