0

In my project deployed on tomcat there are two Wars. I have to redirect the request from one war to another war on a UI action. It is currently based on Spring MVC architecture. So I have added this piece of code in the first war to redirect the requests to my other war, but was unable to redirect it.

@Controller
@RequestMapping(value = "/monetize")
public class MyFirstWarController {
    private static final Logger logger = LoggerFactory.getLogger(MyFirstWarController.class);

    @Autowired
    private ServletContext servletContext;

    @RequestMapping(value = "/dashboard", method = RequestMethod.GET)
    public String showConsumerInterests(HttpServletRequest request, Model model) {
        //WebApplicationContextUtils.getRequiredWebApplicationContext(request.getSession().getServletContext());
        logger.info("In the First War Servlet Context");

        servletContext = servletContext.getContext("/monetize");
        return "monetize/dashboard";
    }

} 

I am trying to reach Controller of my Second War, where I have provided the MVC controller for the request http://MyLocalHost:8080/monetize/dashboard, with a similar Controller like the above. Is there any thing I need to provide in the ViewResolver. I couldn't find any solution to this on the net.

tereško
  • 58,060
  • 25
  • 98
  • 150
suman35
  • 45
  • 1
  • 11
  • http://docs.spring.io/spring/docs/4.0.x/spring-framework-reference/htmlsingle/#mvc-redirecting-redirect-view – JB Nizet Aug 26 '14 at 18:14
  • possible duplicate of [Redirect to an external URL from controller action in Spring MVC](http://stackoverflow.com/questions/17955777/redirect-to-an-external-url-from-controller-action-in-spring-mvc) – Hamid Samani Aug 26 '14 at 18:24

1 Answers1

0

In this case you should add redirect: prefix into returned value of your controller.

For example:

@RequestMapping(value = "/dashboard", method = RequestMethod.GET)
public String showConsumerInterests(HttpServletRequest request, Model model) {
    //any logic
    return "redirect:http://localhost:8080/monetize/dashboard";
}

Also check this.

Community
  • 1
  • 1
Hamid Samani
  • 445
  • 5
  • 15