0

I'm programming a web application in Netbeans 8.0.2 and I'm currently working on setting up the Controller Servlet. I'm a student and I have a question regarding the doPost and doGet methods.

I know:

  • URL patterns associated primarily with page requests are managed by the doGet method.

For example, /category, /viewCart, and /checkout result in the display of the category, cart, and checkout pages.)

  • URL patterns associated with form submits and the transport of sensitive user data (e.g., /addToCart, /updateCart, and /purchase) are managed by the doPost method.

SO

According to that information, I was wondering where should I put these following actions: viewAccount and viewOrderHistory? To my knowledge they both contains data (customer's information) so I would put them under doPost.

But I'm confused because the action viewCart is under doGet... and according to the information I have, viewCart action will contain data once the customer added a product in their cart. So why is it under doGet instead of doPost?

Should I put every action that starts with "view" under doGet, regardless if they handle data or not?

Also, where should I put logout action? doPost or doGet?

I hope I have been cleared enough so you can understand me.

Thanks a lot!

user23524697
  • 127
  • 1
  • 5
  • 17

1 Answers1

1

First you can use doGet and doPost according to your need, you should know that GET and POST differences source1,source2

Should I put every action that starts with "view" under doGet, regardless if they handle data or not?

  • Yes it make sense to put all view data to doGet first, important part in here if you don't want your data seen at url make your calls via method=POST

Also, where should I put logout action? doPost or doGet?

  • LogOut if you didn't put any user information at logout process(normally you shouldn't be) it does not matter to use doGet or doPost.
Community
  • 1
  • 1
erhun
  • 3,133
  • 2
  • 29
  • 40