2

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.

1
  • 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. Commented Jul 2, 2015 at 14:48

1 Answer 1

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;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.