[英]Spring MVC redirection is adding some parameters in the url
I have a spring mvc web application with the following code. 我有一个带有以下代码的spring mvc Web应用程序。 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 Spring MVC Controller:重定向,而没有将参数添加到我的网址中
I have no clue of which part of code is adding the parameters. 我不知道代码的哪一部分添加了参数。
You can make your method return View
instead of String
and then create RedirectView
in a way: 您可以使方法返回
View
而不是String
,然后以以下方式创建RedirectView
:
RedirectView view = new RedirectView(url);
view.setExposeModelAttributes(false);
return view;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.