我一直在用Spring创建一个表单。我曾经有一个页面工作正常,所有的验证工作正常,重定向带我回到有模型的页面,错误,所有的字段都填好了。
但是,现在,因为我已经创建了另一个更基于JS的页面,它将重定向到我的初始应用程序表单。
(如果有任何不同,它使用sessionstorage)
我的控制器#图1
@RequestMapping(value = "/newApplication", method = RequestMethod.GET)
public String retryApplication(Model theModel) {
if (!theModel.containsAttribute("applicant")) {
theModel.addAttribute("applicant", new Applicant());
} else {
Applicant theApplicant = new Applicant();
theModel.addAttribute("applicant", theApplicant);
}
return "application-form";
}
@RequestMapping(method = RequestMethod.POST)
public String doSendEmail(HttpServletRequest request,@Valid @ModelAttribute("applicant") Applicant Applicant,
BindingResult result, RedirectAttributes redirectAttributes)throws Exception {
//checks form for errors
if(result.hasErrors()) {
System.out.println("found errors");
redirectAttributes.addFlashAttribute("org.springframework.validation.BindingResult.applicant", result);
System.out.println("adding flashattribute to binding result");
redirectAttributes.addFlashAttribute("applicant", Applicant);
System.out.println("adding flashattribute to applicant");
return "redirect:/newApplication";
}