我在重定向外部网址后获取属性时遇到问题。重定向到外部url时,我将属性值设置为null,就像我将这些方法放在同一个webapp中一样。
[请指出我在做什么错,或者是否有任何办法,以便我可以将属性传递给重定向的url并使用它。
我不希望属性显示为Queryparams。
示例代码如下。
// app1中的控制器
@PostMapping("/redirect")
public RedirectView next(RedirectAttributes redirectAttributes, Model model, HttpServletResponse response, HttpServletRequest request) {
request.setAttribute("payment",new Payment("1","2","3"));
redirectAttributes.addAttribute("test", "test");
redirectAttributes.addFlashAttribute("message", "Successfully changed..");
redirectAttributes.addFlashAttribute("payment1",new Payment("1","2","3"));
request.setAttribute(
View.RESPONSE_STATUS_ATTRIBUTE, HttpStatus.TEMPORARY_REDIRECT);
RedirectView redirectView = new RedirectView("redirect:http://localhost:8085/redirectedPostToPost", true);
redirectView.addStaticAttribute("payment",new Payment("1","2","3"));
return redirectView;
}
// app2的控制器。
@PostMapping("/redirectedPostToPost")
public ModelAndView redirectedPostToPost(@ModelAttribute("message") String message,@ModelAttribute("payment") Payment payment,@ModelAttribute("payment1") Payment payment1, RedirectAttributes redirectAttributes,Model model, HttpServletResponse httpServletResponse, HttpServletRequest request, ModelAndView modelview) {
logger.info("in redirectedPostToPost:{} : modelview:{}", model, modelview.getModel());
Map<String, ?> inputFlashMap = RequestContextUtils.getInputFlashMap(request);
logger.info("flashmap:{}", inputFlashMap);
return new ModelAndView("about");
}
谢谢你们。
HTTP仅支持GET方法重定向。这是详细信息enter link description here
[一种解决方法是,您发送数据以在视图中创建视图并创建FORM,然后使用javascript自动提交表单重定向URL。您可以使用所有表单隐藏字段。这将是一个白页。