【发布时间】:2015-07-02 14:46:40
【问题描述】:
我有一个带有以下代码的 spring mvc web 应用程序。当用户未登录时,我将发送一个图块视图。
当用户登录时,我会重定向到特定的 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
我尝试了以下网址,但没有成功。
Spring MVC Controller: Redirect without parameters being added to my url
我不知道是哪部分代码添加了参数。
【问题讨论】:
-
为什么不把这些页面放在一个 JSP 中并使用像这样的返回“nameofjspwithoutextension”。所以 admin.jsp 将返回“admin”;。我也是这样做的,而且效果很好。
标签: java spring jsp spring-mvc redirect