diff --git a/spring-rest/src/main/java/org/baeldung/web/controller/redirect/RedirectController.java b/spring-rest/src/main/java/org/baeldung/web/controller/redirect/RedirectController.java
index 1b87ab2816..472c0c8bf5 100644
--- a/spring-rest/src/main/java/org/baeldung/web/controller/redirect/RedirectController.java
+++ b/spring-rest/src/main/java/org/baeldung/web/controller/redirect/RedirectController.java
@@ -13,41 +13,40 @@ import org.springframework.web.servlet.view.RedirectView;
@RequestMapping("/")
public class RedirectController {
- @RequestMapping(value = "/redirectWithXMLConfig", method = RequestMethod.GET)
- public ModelAndView redirectWithUsingXMLConfig(final ModelMap model) {
- model.addAttribute("attribute", "redirectWithXMLConfig");
- return new ModelAndView("RedirectedUrl", model);
- }
+ @RequestMapping(value = "/redirectWithXMLConfig", method = RequestMethod.GET)
+ public ModelAndView redirectWithUsingXMLConfig(final ModelMap model) {
+ model.addAttribute("attribute", "redirectWithXMLConfig");
+ return new ModelAndView("RedirectedUrl", model);
+ }
- @RequestMapping(value = "/redirectWithRedirectPrefix", method = RequestMethod.GET)
- public ModelAndView redirectWithUsingRedirectPrefix(final ModelMap model) {
- model.addAttribute("attribute", "redirectWithRedirectPrefix");
- return new ModelAndView("redirect:/redirectedUrl", model);
- }
+ @RequestMapping(value = "/redirectWithRedirectPrefix", method = RequestMethod.GET)
+ public ModelAndView redirectWithUsingRedirectPrefix(final ModelMap model) {
+ model.addAttribute("attribute", "redirectWithRedirectPrefix");
+ return new ModelAndView("redirect:/redirectedUrl", model);
+ }
- @RequestMapping(value = "/redirectWithRedirectAttributes", method = RequestMethod.GET)
- public RedirectView redirectWithRedirectAttributes(final RedirectAttributes redirectAttributes) {
- redirectAttributes.addFlashAttribute("flashAttribute", "redirectWithRedirectAttributes");
- redirectAttributes.addAttribute("attribute", "redirectWithRedirectAttributes");
- return new RedirectView("redirectedUrl");
- }
+ @RequestMapping(value = "/redirectWithRedirectAttributes", method = RequestMethod.GET)
+ public RedirectView redirectWithRedirectAttributes(final RedirectAttributes redirectAttributes) {
+ redirectAttributes.addFlashAttribute("flashAttribute", "redirectWithRedirectAttributes");
+ redirectAttributes.addAttribute("attribute", "redirectWithRedirectAttributes");
+ return new RedirectView("redirectedUrl");
+ }
- @RequestMapping(value = "/redirectWithRedirectView", method = RequestMethod.GET)
- public RedirectView redirectWithUsingRedirectView(final ModelMap model) {
- model.addAttribute("attribute", "redirectWithRedirectView");
- return new RedirectView("redirectedUrl");
- }
+ @RequestMapping(value = "/redirectWithRedirectView", method = RequestMethod.GET)
+ public RedirectView redirectWithUsingRedirectView(final ModelMap model) {
+ model.addAttribute("attribute", "redirectWithRedirectView");
+ return new RedirectView("redirectedUrl");
+ }
- @RequestMapping(value = "/forwardWithForwardPrefix", method = RequestMethod.GET)
- public ModelAndView forwardWithUsingForwardPrefix(final ModelMap model) {
- model.addAttribute("attribute", "redirectWithForwardPrefix");
- return new ModelAndView("forward:/redirectedUrl", model);
- }
+ @RequestMapping(value = "/forwardWithForwardPrefix", method = RequestMethod.GET)
+ public ModelAndView forwardWithUsingForwardPrefix(final ModelMap model) {
+ model.addAttribute("attribute", "redirectWithForwardPrefix");
+ return new ModelAndView("forward:/redirectedUrl", model);
+ }
- @RequestMapping(value = "/redirectedUrl", method = RequestMethod.GET)
- public ModelAndView redirection(final ModelMap model,
- @ModelAttribute("flashAttribute") final Object flashAttribute) {
- model.addAttribute("redirectionAttribute", flashAttribute);
- return new ModelAndView("redirection", model);
- }
+ @RequestMapping(value = "/redirectedUrl", method = RequestMethod.GET)
+ public ModelAndView redirection(final ModelMap model, @ModelAttribute("flashAttribute") final Object flashAttribute) {
+ model.addAttribute("redirectionAttribute", flashAttribute);
+ return new ModelAndView("redirection", model);
+ }
}
\ No newline at end of file
diff --git a/spring-rest/src/main/webapp/WEB-INF/api-servlet.xml b/spring-rest/src/main/webapp/WEB-INF/api-servlet.xml
index 9bcff1dfe3..5afc637ece 100644
--- a/spring-rest/src/main/webapp/WEB-INF/api-servlet.xml
+++ b/spring-rest/src/main/webapp/WEB-INF/api-servlet.xml
@@ -1,31 +1,33 @@
-
+
-
+
-
+
-
-
-
- /WEB-INF/spring-views.xml
-
-
-
+
+
+
+ /WEB-INF/spring-views.xml
+
+
+
-
-
-
+
+
+
-
-
+
+
-
+
+
+
+
-
\ No newline at end of file
diff --git a/spring-rest/src/main/webapp/WEB-INF/spring-views.xml b/spring-rest/src/main/webapp/WEB-INF/spring-views.xml
index 83c7828d9a..2944828d6d 100644
--- a/spring-rest/src/main/webapp/WEB-INF/spring-views.xml
+++ b/spring-rest/src/main/webapp/WEB-INF/spring-views.xml
@@ -1,10 +1,10 @@
-
+
-
-
-
+
+
+
\ No newline at end of file
diff --git a/spring-rest/src/main/webapp/WEB-INF/web.xml b/spring-rest/src/main/webapp/WEB-INF/web.xml
index 48d4b8fe61..c28bb9a20a 100644
--- a/spring-rest/src/main/webapp/WEB-INF/web.xml
+++ b/spring-rest/src/main/webapp/WEB-INF/web.xml
@@ -1,42 +1,41 @@
-
+ http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0"
+>
- Spring MVC Application
+ Spring MVC Application
-
-
- contextClass
-
+
+
+ contextClass
+
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
-
-
- contextConfigLocation
- org.baeldung.config
-
+
+
+ contextConfigLocation
+ org.baeldung.config
+
-
- org.springframework.web.context.ContextLoaderListener
-
+
+ org.springframework.web.context.ContextLoaderListener
+
-
-
- api
- org.springframework.web.servlet.DispatcherServlet
- 1
-
-
- api
- /
-
+
+
+ api
+ org.springframework.web.servlet.DispatcherServlet
+ 1
+
+
+ api
+ /
+
-
-
-
+
+
+
-
\ No newline at end of file
+
diff --git a/spring-rest/src/test/java/org/baeldung/web/controller/redirect/RedirectControllerTest.java b/spring-rest/src/test/java/org/baeldung/web/controller/redirect/RedirectControllerTest.java
index c1ce21bef1..ab2b9f3f87 100644
--- a/spring-rest/src/test/java/org/baeldung/web/controller/redirect/RedirectControllerTest.java
+++ b/spring-rest/src/test/java/org/baeldung/web/controller/redirect/RedirectControllerTest.java
@@ -26,56 +26,42 @@ import org.springframework.web.context.WebApplicationContext;
@WebAppConfiguration
public class RedirectControllerTest {
- private MockMvc mockMvc;
+ private MockMvc mockMvc;
- @Autowired
- protected WebApplicationContext wac;
+ @Autowired
+ protected WebApplicationContext wac;
- @Before
- public void setup() {
- mockMvc = webAppContextSetup(wac).build();
- }
+ @Before
+ public void setup() {
+ mockMvc = webAppContextSetup(wac).build();
+ }
- @Test
- public void whenRedirectOnUrlWithUsingXMLConfig_thenStatusRedirectionAndRedirectedOnUrl() throws Exception {
- mockMvc.perform(get("/redirectWithXMLConfig")).andExpect(status().is3xxRedirection())
- .andExpect(view().name("RedirectedUrl"))
- .andExpect(model().attribute("attribute", is("redirectWithXMLConfig")))
- .andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithXMLConfig"));
- }
+ @Test
+ public void whenRedirectOnUrlWithUsingXMLConfig_thenStatusRedirectionAndRedirectedOnUrl() throws Exception {
+ mockMvc.perform(get("/redirectWithXMLConfig")).andExpect(status().is3xxRedirection()).andExpect(view().name("RedirectedUrl")).andExpect(model().attribute("attribute", is("redirectWithXMLConfig")))
+ .andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithXMLConfig"));
+ }
- @Test
- public void whenRedirectOnUrlWithUsingRedirectPrefix_thenStatusRedirectionAndRedirectedOnUrl() throws Exception {
- mockMvc.perform(get("/redirectWithRedirectPrefix")).andExpect(status().is3xxRedirection())
- .andExpect(view().name("redirect:/redirectedUrl"))
- .andExpect(model().attribute("attribute", is("redirectWithRedirectPrefix")))
- .andExpect(redirectedUrl("/redirectedUrl?attribute=redirectWithRedirectPrefix"));
- }
+ @Test
+ public void whenRedirectOnUrlWithUsingRedirectPrefix_thenStatusRedirectionAndRedirectedOnUrl() throws Exception {
+ mockMvc.perform(get("/redirectWithRedirectPrefix")).andExpect(status().is3xxRedirection()).andExpect(view().name("redirect:/redirectedUrl")).andExpect(model().attribute("attribute", is("redirectWithRedirectPrefix")))
+ .andExpect(redirectedUrl("/redirectedUrl?attribute=redirectWithRedirectPrefix"));
+ }
- @Test
- public void whenRedirectOnUrlWithUsingRedirectAttributes_thenStatusRedirectionAndRedirectedOnUrlAndAddedAttributeToFlashScope()
- throws Exception {
- mockMvc.perform(get("/redirectWithRedirectAttributes")).andExpect(status().is3xxRedirection())
- .andExpect(flash().attribute("flashAttribute", is("redirectWithRedirectAttributes")))
- .andExpect(model().attribute("attribute", is("redirectWithRedirectAttributes")))
- .andExpect(model().attribute("flashAttribute", is(nullValue())))
- .andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectAttributes"));
- }
+ @Test
+ public void whenRedirectOnUrlWithUsingRedirectAttributes_thenStatusRedirectionAndRedirectedOnUrlAndAddedAttributeToFlashScope() throws Exception {
+ mockMvc.perform(get("/redirectWithRedirectAttributes")).andExpect(status().is3xxRedirection()).andExpect(flash().attribute("flashAttribute", is("redirectWithRedirectAttributes")))
+ .andExpect(model().attribute("attribute", is("redirectWithRedirectAttributes"))).andExpect(model().attribute("flashAttribute", is(nullValue()))).andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectAttributes"));
+ }
- @Test
- public void whenRedirectOnUrlWithUsingRedirectView_thenStatusRedirectionAndRedirectedOnUrlAndAddedAttributeToFlashScope()
- throws Exception {
- mockMvc.perform(get("/redirectWithRedirectView")).andExpect(status().is3xxRedirection())
- .andExpect(model().attribute("attribute", is("redirectWithRedirectView")))
- .andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectView"));
- }
+ @Test
+ public void whenRedirectOnUrlWithUsingRedirectView_thenStatusRedirectionAndRedirectedOnUrlAndAddedAttributeToFlashScope() throws Exception {
+ mockMvc.perform(get("/redirectWithRedirectView")).andExpect(status().is3xxRedirection()).andExpect(model().attribute("attribute", is("redirectWithRedirectView"))).andExpect(redirectedUrl("redirectedUrl?attribute=redirectWithRedirectView"));
+ }
- @Test
- public void whenRedirectOnUrlWithUsingForwardPrefix_thenStatusOkAndForwardedOnUrl() throws Exception {
- mockMvc.perform(get("/forwardWithForwardPrefix")).andExpect(status().isOk())
- .andExpect(view().name("forward:/redirectedUrl"))
- .andExpect(model().attribute("attribute", is("redirectWithForwardPrefix")))
- .andExpect(forwardedUrl("/redirectedUrl"));
- }
+ @Test
+ public void whenRedirectOnUrlWithUsingForwardPrefix_thenStatusOkAndForwardedOnUrl() throws Exception {
+ mockMvc.perform(get("/forwardWithForwardPrefix")).andExpect(status().isOk()).andExpect(view().name("forward:/redirectedUrl")).andExpect(model().attribute("attribute", is("redirectWithForwardPrefix"))).andExpect(forwardedUrl("/redirectedUrl"));
+ }
}