Ozgur
Ozgur

Reputation: 137

Spring MVC Redirect to HTTPs site after successful post form

We would like to redirect user after a successful post to secure pages.

@RequestMapping(value="/myapp", method=POST) 
public String processForm(Formbean formbean){
   // redirect to https ?????? 
   return "redirect:/secure"; 
}

Is there any easy way to make it without writing full redirection url?

Upvotes: 2

Views: 2988

Answers (2)

Sig
Sig

Reputation: 5188

Not too sure you can do that without specifying the entire url in the redirect string.

Perhaps its best to add a security constraint for that url in your web.xml setting the transport-guarantee to CONFIDENTIAL. If your servlet container is setup correctly then that should be all you need to get it to do the automatic redirect for you.

<security-constraint>
  <web-resource-collection>
    <web-resource-name>Secure page</web-resource-name>
    <url-pattern>/securePage.html</url-pattern>
  </web-resource-collection>
  <user-data-constraint>
    <transport-guarantee>CONFIDENTIAL</transport-guarantee>
  </user-data-constraint>
</security-constraint>

Upvotes: 0

fasseg
fasseg

Reputation: 17761

you can check out RedirectView and the contextRelative parameter in the Spring API Docs:

http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/web/servlet/view/RedirectView.html

hope that helped...

Upvotes: 2

Related Questions