SpringMVC中 Redirect后地址栏带参数, 怎么把它去掉.

程序中需要一个退出登录的方法, 代码:

 @RequestMapping(value="/logout", method=RequestMethod.GET)
 public String Logout( HttpSession session){
  if(null != session.getAttribute(LOGIN_USERNAME)){
   String username = session.getAttribute(LOGIN_USERNAME).toString();
   session.removeAttribute(LOGIN_USERNAME);
  }
 
  return InternalResourceViewResolver.REDIRECT_URL_PREFIX + "login";
 }
 
这个退出登录的方法, 目标是将session中的用户名删除, 再重定向到登录界面就可以了. 但重定向后地址栏里是有参数的(形如 login?loginUsername=adm 这种).

原因:
官方文档, The RequestMappingHandlerAdapter provides a flag called "ignoreDefaultModelOnRedirect" that can be used to indicate the content of the default Model should never be used if a controller method redirects. Instead the controller method should declare an attribute of type RedirectAttributes or if it doesn’t do so no attributes should be passed on to RedirectView. Both the MVC namespace and the MVC Java config keep this flag set to false in order to maintain backwards compatibility. However, for new applications we recommend setting it to true

解决方法: springMVC的配置文件中注解开关中配置"ignoreDefaultModelOnRedirect"变量为true, 如下:
<mvc:annotation-driven ignoreDefaultModelOnRedirect="true"/>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值