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"/>
- 使用springmvc redirect跳转地址时中文参数为空
- 求解:在springMVC中,怎么根据参数来调用不同的方法?!但是,不是用if...else...!!!
- SpringMVC利用return new ModelAndView(new RedirectView("xxx.do"), Map map)重定向传递多参数
- 关于springmvc 的 RedirectAttributes及分布式的redirect参数传递
- springMVC怎么接受前台传过来的多种类型参数?(集合、实体、单个参数)
- springmvc之RedirectAttributes重定向带参数设置
- SpringMVC重定向(redirect)传参数的实现
- springmvc书写rest风格地址栏参数
- webStrorm js文件里 怎么去掉参数的下划线
- springMVC怎么接收日期类型的参数?
- 怎么用javascript获取到地址栏url中的参数
- springMVC使用redirect导致URL加上无关参数
- springMVC重定向redirect传递参数
- Springmvc重定向参数以及表单提交问题的认识
- springmvc(十五)springmvc注解开发-springmvc参数绑定-list绑定
- SpringMVC的各种参数绑定方式
- 深度学习方法(六):神经网络weight参数怎么初始化
- 解决在地址栏中传递中文汉字参数乱码的问题:
- SpringMVC入门及系列教程(五)-响应处理&响应参数处理&SpringMVC作用域对象&SpringMVC原生Servlet对象
- springmvc带参数链接跳转,实现单一样式容器