Spring MVC “redirect:” prefix always redirects to http — how do I make it stay on https?

后端 未结 7 1218
鱼传尺愫
鱼传尺愫 2020-12-07 16:28

I solved this myself, but I spent so long discovering such a simple solution, I figured it deserved to be documented here.

I have a typical Spring 3 MVC setup with

7条回答
  •  不思量自难忘°
    2020-12-07 17:05

    The short answer is, set the InternalResourceViewResolver's redirectHttp10Compatible property to false:

    
      
      
      
      
    
    

    You could do this on a per-request basis instead, by having your handler method return View instead of String, and creating the RedirectView yourself, and calling setHttp10Compatible(false).

    (It turns out the culprit is HttpServletResponse.sendRedirect, which the RedirectView uses for HTTP 1.0 compatible redirects, but not otherwise. I guess this means it's dependent on your servlet container's implementation (?); I observed the problem in both Tomcat and Jetty.)

提交回复
热议问题