BAEL-3821: Add new section in "Spring redirect and forward" article (#10502)
This commit is contained in:
parent
c29b355b02
commit
5832baeccc
|
@ -64,5 +64,11 @@ public class RedirectController {
|
|||
public ModelAndView redirectedPostToPost() {
|
||||
return new ModelAndView("redirection");
|
||||
}
|
||||
|
||||
|
||||
@RequestMapping(value="/forwardWithParams", method = RequestMethod.GET)
|
||||
public ModelAndView forwardWithParams(HttpServletRequest request) {
|
||||
request.setAttribute("param1", "one");
|
||||
request.setAttribute("param2", "two");
|
||||
return new ModelAndView("forward:/forwardedWithParams");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package com.baeldung.sampleapp.web.controller.redirect;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.servlet.mvc.support.RedirectAttributes;
|
||||
import org.springframework.web.servlet.view.RedirectView;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/")
|
||||
public class RedirectParamController {
|
||||
|
||||
@RequestMapping(value = "/forwardedWithParams", method = RequestMethod.GET)
|
||||
public RedirectView forwardedWithParams(final RedirectAttributes redirectAttributes, HttpServletRequest request) {
|
||||
|
||||
redirectAttributes.addAttribute("param1", request.getAttribute("param1"));
|
||||
redirectAttributes.addAttribute("param2", request.getAttribute("param2"));
|
||||
|
||||
redirectAttributes.addAttribute("attribute", "forwardedWithParams");
|
||||
return new RedirectView("redirectedUrl");
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue