开发者

Spring redirect: prefix issue

I have an application which uses Spring 3. I have a view resolver which builds my views based on a String. So in my controllers I have methods like this one.

@RequestMapping(...)
public String method(){
  //Some proccessing
  return "tiles:tileName"
}

I need to return a RedirectView to solve the duplicate submission due to updating the page in the browser, so I have thought to use Spring redirect: prefix. The problem is that it only redirects when I user a URL alter the prefix (not with a name a resolver can understand). I wanted to do something like this:

@RequestMapping(...)
public String method(){
  //Some proccessing
  return "redirect:tiles:tileName"
}

Is there any way to use 开发者_JAVA百科RedirectView with the String (the resolvable view name) I get from the every controller method?

Thanks


the call prefixed by redirect: is a url, which is sent in a standard browser 302 redirect. you can't redirect to a view, because a view isn't a url. instead you'll need a new servelet mapping to a 'success' view and then redirect to that instead

@RequestMapping("processing.htm")
public String method(){
  //Some proccessing
  return "redirect:success.htm"
}

@RequestMapping("success.htm")
public String method(){
  return "tiles:tileName"
}

this case works fine when you just need to show a 'thank you' page, which requires no specific data from the processing stage. however, if your success page needs to show some information from the processing, there are 2 ways to do it.

1) pass the information in the url as a get post ("redirect:success.htm?message=hi"). this is incredibly hackable, and thus highly unrecommended.

2) the better way is to store information in the http session, using @SessionAttributes and @ModelAttribute

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜