• 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

Adding redirect-after-post behavior with redirect:

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a small Spring MVC project that implements serving and processing functionality. It has a Member class that is used for a form bean. The Member class just has tow String fields, firstName and lastName. The following is a form to submit a Member for a nomination:



The following jsp displays a thank you for submitting the nominee:



My NomineeController is :



Here is my config file to define the controllers:



This example is from the book Spring In Practice by Wheeler and White.

When you enter a nominee's first and last name on form.jsp and hit submit, the processFormData() method is called in the NomineeController. When this completes, it returns the string "nominee/thanks" which is resolved to the /WEB-INF/jsp/nominee/thans.jsp page above. The URL is /sip/main/nominee/thanks and displays the first and last name entered on the form.

The book indicates to add redirect-after-post behavior, simply pre-pend the logical view name (thanksViewName) with "redirect:". So I tried to do this. If I change p:thanksViewName="nominee/thanks"/> to p:thanksViewName="redirect:nominee/thanks/>" the URL the browswer goes to is
/main/nominee/nominee/thanks which is incorrect, so I get a 404. If I use p:thanksViewName="redirect:/sip/main/nominee/thanks" the browser is redirected to the correct URL, but the first and last names are both null.

What is the correct way to append "redirect:" on to the logical view name so I get the correct URL and firstname and lastname are those entered on the form?
Thanks Much in advance
 
Rancher
Posts: 2759
32
Eclipse IDE Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Mike,

You might be misunderstanding the PostRedirectGet pattern. When you do a PostRedirectGet, you send the parameters of the form in a Post Request. THe Post request saves the data, and then sends a redirect to the Get request. The Get request gets the data that needs to be shown in the "result" page and displays it. You never use Get request to save data. Get request (as the name says) should always be used to Get data. Post request (as the name says) should be used to post data to the server

Or, put it in more technical language. GET requests should be idempotent. They shouldn;t change the state of the system.
 
Mike Tabak
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jayesh A Lalwani wrote:Mike,

You might be misunderstanding the PostRedirectGet pattern. When you do a PostRedirectGet, you send the parameters of the form in a Post Request. THe Post request saves the data, and then sends a redirect to the Get request. The Get request gets the data that needs to be shown in the "result" page and displays it. You never use Get request to save data. Get request (as the name says) should always be used to Get data. Post request (as the name says) should be used to post data to the server

Or, put it in more technical language. GET requests should be idempotent. They shouldn;t change the state of the system.



Jayesh,

Thanks for your reply. As I said, this example is from a book. At this point I guess I'll have to do some research and try to better understand what it the pattern is an what the author had in mind. Thanks.
 
It runs on an internal combustion engine. This ad does not:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic