• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
  • Mike London

ModelAndView: redirect as 301 (Permanent) not 302 (Temp)?

Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So, I'm still kind of new to Spring, having done a good amount of work on it, but never started much from scratch, so I might be missing something obvious

I believe that this line of code:
return new ModelAndView("redirect:" + getNewURL());

is what is responsible for doing a 302 (Moved Temporarily) redirect .

i don't know if this is kind of a "built in" to Spring behavior or if there's some kind of configuration that gets that to work, but I need to get a similar redirection going as a 301 (Moved Permanently) redirect, since we believe that search engines prefer that.

I'm not sure where to find out how the redirection is supposed to be setup, what I would have to do to get the HTTP headers right for the other kind of redirect... it looks like I'm pretty close to the top of "our" program stack, where Spring etc's Filter Chain kicks in, but i could be missing something...

kirk israel
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok, so it seems like that whole
thing is just a builtin shortcut, I assume the view in question is a RedirectView()

According to http://jira.springframework.org/browse/SPR-5468 it seems like sometime soonish I should be able to write

ModelAndView redirectModelAndView = new ModelAndView();
RedirectView redirectView = new RedirectView(brandService.getBaseHref(request));
return redirectModelAndView;

but not yet.

http://forum.springsource.org/archive/index.php/t-16370.html tells me I should be able to extend RedirectView and override sendRedirect with:
response.setHeader("Location", response.encodeRedirectURL(targetUrl));

but for now my lead just says

response.setHeader("Location", brandService.getBaseHref(request));
response.setHeader("Connection", "close");
return null;

and Spring will take that null ModelAndView and just let the other stuff pass through.

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic