我有一个本地运行的 Spring Web 应用程序。它工作得非常好,并且在重定向时将 flash 属性完美地传递到另一个 Controller 。
当我在 openshift 上提出这个问题时,使用 https 路由时,flash 属性功能会停止工作。不过,如果我使用 http 路由,它仍然可以正常工作。
这是我的重定向传递方法,它接受路径中的 id,执行一些逻辑并重定向到/foo 端点,传递 someVariable。
@GetMapping("/foo/{someId}")
public ModelAndView redirectFoo(@RequestHeader HttpHeaders headers, @PathVariable(value = "someId") String someId, RedirectAttributes attributes) {
//..some logic
attributes.addFlashAttribute("someVariable", someVariable);
return new ModelAndView("redirect:/foo");
}
redirectFoo 重定向到/foo 并通过 flash 属性传入 someVariable 到/foo
@GetMapping("/foo")
public ModelAndView get(@RequestHeader HttpHeaders headers, @ModelAttribute("someVariable") String someVariable) {
//...some logic with someVariable...
return new ModelAndView("foo");
}
这一切在本地都运行得很好。但是当我在 openshift 上安装它时,它无法正常工作。
*编辑:这似乎不是一个 openshift 问题,而是一个 https 问题。如果我使用 http 路由,则 flash 属性可以正常工作。如果我使用 https 路由,他们不会。
最佳答案
正如 Graham 在评论中所说,这是我的应用程序重定向到 http
而不是 https
的问题。为了解决这个问题,我只需要将重定向方法更改为
@GetMapping("/foo/{someId}")
public RedirectView redirectFoo(@RequestHeader HttpHeaders headers, @PathVariable(value = "someId") String someId, RedirectAttributes attributes) {
//..some logic
attributes.addFlashAttribute("someVariable", someVariable);
RedirectView redirectView = new RedirectView("/foo");
redirectView.setHttp10Compatible(false);
return redirectView;
}
关于java - Flash 属性不适用于 https - 适用于 http,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54757027/