Is it possible to change URL when returning ModelAndView from WEB-INF?

2.3k views Asked by At

I'm using Spring MVC and I'm wondering is it possible to change URL when I return ModelAndView (the view is situated at the WEB-INF folder, so redirecting to it is not working) from the controller? I mean when I return it the URL is the previous one, and its obvious because dispatcher is working, not the redirecting.

@RequestMapping(value = "/login", method = RequestMethod.POST)
    public ModelAndView authenticate(@RequestParam("login") String login, @RequestParam("password") String password) {
        ModelAndView modelAndView = new ModelAndView();
        User user = userDao.getUserByLogin(login);
        if (user != null && user.getPassword().equals(password)) {
            modelAndView.addObject("user", user);
            modelAndView.setViewName("home");
        }
        return modelAndView;
    }

So my home model is in WEB-INF folder, so return redirect:/home will not work for it. Yes, I can redirect it with return home, but in that case the URL will not change.

1

There are 1 answers

3
sridhar On

Use redirect:/url to some other method and return the view.

When redirecting the model attributes won't available in new method so to get that in redirected method set it in RedirectFlashAttributes.

Hope it helps.