2

When I use return redirect in methods, spring automatically adds my Model variables like get params to url. I've found solution here Spring MVC Controller: Redirect without parameters being added to my url

but unfortunately it doesn't work with spring 3.2

Also i've found following

When upgrading to spring-mvc-4.0.xsd, you should replace enableMatrixVariables and ignoreDefaultModelOnRedirect with enable-matrix-variables and ignore-default-model-on-redirect respectively.

but when i add this to my mvc-dispatcher.xml my IDE says that attribute is not allowed here.

Any solutions for Spring 3.2?

Community
  • 1
  • 1
user3127896
  • 6,323
  • 15
  • 39
  • 65
  • 1
    What is your question? –  Oct 03 '14 at 08:03
  • 1
    What have you tried exactly? It seems that `ignore-default-model-on-redirect ` is actually what you should use. – alain.janinm Oct 03 '14 at 08:38
  • In Spring 3.2, it actually seems that ignoreDefaultModelOnRedirect is what should be used. – Hugo G. Oct 03 '14 at 10:17
  • Hugo G. what that i got when i try to deploy application org.xml.sax.SAXParseException; lineNumber: 71; columnNumber: 65; cvc-complex-type.3.2.2: Attribute 'ignoreDefaultModelOnRedirect' is not allowed to appear in element 'mvc:annotation-driven'. – user3127896 Oct 04 '14 at 12:58

3 Answers3

3

If you are using java configuration add following to your WebMvcConfigurerAdapter child class:

@Autowired
private RequestMappingHandlerAdapter requestMappingHandlerAdapter;

@PostConstruct
public void init() {
    requestMappingHandlerAdapter.setIgnoreDefaultModelOnRedirect(true);
}
irisk
  • 111
  • 1
  • 9
2

You can clear your model before the redirect :

@RequestMapping(...)
public String doSomething(Model model, ...)
{
    // ....
    model.asMap().clear();
    return "redirect:list";
}

You can see other solutions here :

Spring 3.0 MVC :Redirect without parameters being added to my url

Community
  • 1
  • 1
Hugo G.
  • 636
  • 6
  • 21
  • Sorry, I understood you did not want to pass your model attribute to the redirect URL. Can you be more specific about what you tried, what you get and what you want ? – Hugo G. Oct 03 '14 at 10:03
0

This worked for me. Use this if you do not want your model data to be attached to the url parameter.

@RequestMapping("save/")
public View doSave(...)
{
    ...
    RedirectView redirect = new RedirectView("/success");
    redirect.setExposeModelAttributes(false);
    return redirect;
}

Thanks to reallynic's comment.

Community
  • 1
  • 1
Ram Patra
  • 16,266
  • 13
  • 66
  • 81