java Spring 3.0 MVC:重定向而不将参数添加到我的 url
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17676206/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Spring 3.0 MVC :Redirect without parameters being added to my url
提问by Federico
I'm trying to redirect without parameters being added to my url. I mean after a redirect, my url looks like this: .../success/?param1=xxx¶m2=xxx.
我正在尝试在没有将参数添加到我的 url 的情况下进行重定向。我的意思是重定向后,我的网址如下所示:.../success/?param1=xxx¶m2=xxx。
This issue is exactly the same as this Spring MVC Controller: Redirect without parameters being added to my url
这个问题和这个Spring MVC 控制器完全一样:Redirect without parameters are added to my url
The response https://stackoverflow.com/a/16841663/384984is what I'm looking (ignoreDefaultModelOnRedirect). The problem is that I'm using Spring 3.0. How can I solve it with this Spring version?
响应https://stackoverflow.com/a/16841663/384984就是我正在寻找的(ignoreDefaultModelOnRedirect)。问题是我使用的是 Spring 3.0。我如何用这个 Spring 版本解决它?
回答by NINCOMPOOP
You can simply clear the
Model
map in yourController
method before redirect .model.asMap().clear(); return "redirect:" + yourURL;
Don't expose the model attributes at all.
RedirectView view = new RedirectView(yourURL, true); view.setExposeModelAttributes(false); return new ModelAndView(view);
Hope this linkhelps you in finding a better solution, specially point (4)
HandlerInterceptor
for common reference data within the entire web application
您可以在重定向之前简单地清除方法中的
Model
地图Controller
。model.asMap().clear(); return "redirect:" + yourURL;
根本不要公开模型属性。
RedirectView view = new RedirectView(yourURL, true); view.setExposeModelAttributes(false); return new ModelAndView(view);
希望此链接可以帮助您找到更好的解决方案,特别
HandlerInterceptor
是整个 Web 应用程序中常见参考数据的第(4) 点