Spring MVC (Spring 2.5) Question about Post-Redirect-Get

I have a Spring Annonted Controller that is used to capture information from a form and retrieve a list of search results from a database.

Here is the definition of the method

@RequestMapping(method = RequestMethod.POST, params = {SUBMIT_BTN }) 
public ModelAndView processForm(@ModelAttribute(COMMAND_NAME){


   // 1. Load search results using search parameters from form (Contained in a collection of some sort)


   // 2. Create the ModelAndView 

   // 3. Redirect with RequestView or redirect: to generate a GET. 
}

I think I need to redirect with redirection: since I have a list of items in the collection store in the session. Cannot add this as url request parameter.

Basically, I am trying to prevent problems with the back button, which says that the page has expired. I want to implement a PRG pattern in strings.

I find it hard to carry my head turning POST into GET. Can I just redirect or do I need two methods? Thanks for any help you can provide.

+3
1

GET ( - ) POST, . POST , , GET.

@RequestMapping(value="/myapp", method=GET) 
public String showForm(@ModelAttribute(COMMAND_NAME){
   return "form.jsp";
}

@RequestMapping(value="/myapp", method=POST) 
public String processForm(@ModelAttribute(COMMAND_NAME){
   // do stuff to process for submission
   return "redirect:/myapp";
}

":": Spring HTTP, .

, Spring 2.0, SimpleFormController, .

+6

Source: https://habr.com/ru/post/1755008/


All Articles