The method that receives the post from the shape and then recalculates:@RequestMapping(value = "reports", method = RequestMethod.POST)
public String get2(@RequestParam("param1") String param1,
@RequestParam("param2") String param2,
@RequestParam("param3") String param3,
@RequestParam("param4") String param4,
RedirectAttributes attributes) {
attributes.addFlashAttribute("param3", param3);
attributes.addFlashAttribute("param4", param4);
System.out.println("Редирект с " + param1 + "," + param2 + "," + param3 + "," + param4);
return "redirect:/reports/" + param1 + "/" + param2;
}
This is called after the recount and sends the page of the report:@RequestMapping(value = "reports/{param1}/{param2}", method = RequestMethod.GET)
public String get3(@PathVariable String param1,
@PathVariable String param2,
Model model, HttpServletRequest request) {
//todo тут может быть NPE, если пользователь обновит страницу, добавить обработчик
String param3 = (String) model.asMap().get("param3"); //первый способ
Map<String, ?> flashMap = RequestContextUtils.getInputFlashMap(request);
String param4 = (String) flashMap.get("param4"); //второй способ
System.out.println("Сделать что-то с " + param1 + "," + param2 + "," + param3 + "," + param4);
return "reports";
}
In this method 2 of obtaining parameters and if the user updates the page, NPE may arise and needs to be processed. As far as I don't know, it works.Form on page of previous reply:<form action="/reports" method="post">
First name:<br>
<input type="text" name="param1" value="Mickey"><br>
Last name:<br>
<input type="text" name="param2" value="Mouse"><br>
Second name:<br>
<input type="text" name="param3" value="third"><br>
My name:<br>
<input type="text" name="param4" value="param4Value"><br><br>
<input type="submit" value="Submit">
</form>
Example http://javainsimpleway.com/spring-mvc-redirecting-model-attributes-from-one-controller-to-other-controller/