1

I have a spring mvc web application with the following code. When the user is not logged in I am sending one tiles view.

And when the user is logged in I am redirecting to specific url patterns.

    @RequestMapping(value = "/login", method = RequestMethod.GET)
    public String login() throws IOException {
        if (logger.isDebugEnabled()) {
            logger.debug("Requested with /login mapping");
        }

        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

        if (!(authentication instanceof AnonymousAuthenticationToken)) {
            List<String> userRoles = AuthenticationUtils.getUserRoles();
            if (userRoles.contains("ROLE_ADMIN")) {
                return "redirect:/admin.html";
            } else if (userRoles.contains("ROLE_USER")) {
                return "redirect:/user.html";
            }
        }
        return "template";
    }

I am getting the redirection but with some unexpected parameters. How to remove them?

http://localhost:8081/app/admin.html?total=48&loggedInUserRoles=207

I have tried the following url without success.

Spring MVC Controller: Redirect without parameters being added to my url

I have no clue of which part of code is adding the parameters.

Community
  • 1
  • 1
phoenix
  • 985
  • 3
  • 17
  • 38
  • Why dont you just put those pages inside a JSP and use a return like this return "nameofjspwithoutextension". So admin.jsp would be return "admin";. I do the same and it just works. – We are Borg Jul 02 '15 at 14:48

1 Answers1

2

You can make your method return View instead of String and then create RedirectView in a way:

RedirectView view = new RedirectView(url);
view.setExposeModelAttributes(false);
return view;
Maciej Walkowiak
  • 12,372
  • 59
  • 63