2015-07-02 36 views
0

我有一个spring mvc web应用程序,下面的代码。当用户没有登录时,我发送一个瓷砖视图。春季MVC重定向是在url中添加一些参数

而当用户登录时,我重定向到特定的url模式。

@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"; 
    } 

我得到重定向,但有一些意外的参数。如何删除它们?

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

我已经尝试过下面的url没有成功。

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

我不知道其中的代码部分被添加的参数。

+0

你为什么不只是把JSP中的页面和使用这样的回报“nameofjspwithoutextension”一回。所以admin.jsp会返回“admin”;.我也这样做,它只是工作。 –

回答

2

你可以让你的方法返回View而不是String,然后在某种程度上创造RedirectView

RedirectView view = new RedirectView(url); 
view.setExposeModelAttributes(false); 
return view;