• Post Reply Bookmark Topic Watch Topic
  • New Topic

doPost calling doGet  RSS feed

 
Jason Kwok
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a servlet that has doPost and doGet methods both doing some processing.

- doGet only retrieves database items and forwards them to a view.
- doPost takes in submitted form data and performs CRUD operations with the database.

The above-mentioned operations all work already. What I need help with I'll try and illustrate briefly:

- doGet retrieves and provides a list of all available teachers in a department
- a user can pick a CRUD operation for a particular teacher which leads them to a new page where they can actually perform the CRUD operation. This form data is forwarded to doPost for processing.
- after doPost is finished, it forwards the user to the admin index page with a confirmation notice.

What I would like to do instead... is after doPost finishes processing, if it could call doGet so that the user could be forwarded back to the list of teachers... this will allow the user to see their changes immediately.

To add to this, doGet has to take in a parameter (or in the case of servlet to servlet, an attribute) to determine what to process. For example, I call doGet from a webpage as such: <a href="Instructor?job=list">Show all instructors</a> where 'job' is the parameter and 'list' is the value to trigger the listing function.

Any help with this would be greatly appreciated!!
Jason
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What you describe is usually handled with the so-called P-R-G pattern (Post-Redirect-Get) rather than trying to call doGet from doPost which will likely lead to a lot of weirdness and problems.

This article covers this pattern.
 
Jason Kwok
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear:
I've read your article and it made me chuckle as I recalled my lengthy experiences with the "model-less pattern" and the problems with the refresh button if the controller hands both CRUD/shopping cart operations and JSP page forwarding at the same time.

Thank you so much for the article reference, I think it'll definitely help solve this problem of mine! Lastly, would you happen to have a link pointing to an example of this front controller pattern so I could look over the code?

Thanks again,
Jason
[ December 22, 2006: Message edited by: Jason Kwok ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65833
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ummm, well, errr, ahhhh.

I always intended to write an article going into details about the design of my simple front controller, but I got involved in other writing tasks (see book link below) and haven't yet finished it.

I'm hoping to finish it and get it into the next issue of the JR Journal.

cough, cough.
 
Jason Kwok
Ranch Hand
Posts: 126
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds great... I'll keep an eye of for it when it's published!!

Thanks again,
Jason
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!