0
リダイレクトが正しく機能しません。私は春に非常に新しいので、私は問題を理解することができませんでした。spring mvcを使用してリダイレクトが正しく機能しない
私のフォームを送信するとき、私のコントローラは( "schoolform")submitFormコントローラが呼び出され、別のコントローラに( 'form')フォームコントローラにリダイレクトされますが、ログインコントローラに移動します。どうしてか分かりません ? schoolformをフォームコントローラにリダイレクトしたいと思います。
@RequestMapping(value = "/schoolform", method = RequestMethod.POST)
public String submitForm(@ModelAttribute("school")School school,Model model,HttpServletRequest request,HttpServletResponse resp) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
schoolService.update(school);
System.out.println("Form submitted finaly, No further changes can be made.");
return "redirect:/form.html";
}
@RequestMapping(value = "/form", method = RequestMethod.GET)
public String form(Model model,HttpServletRequest request) {
HttpSession session = request.getSession(true);
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String name = auth.getName(); // get logged in username
System.out.println(name+"--------form page-----");
}
@RequestMapping(value = "/login", method = RequestMethod.GET)
public ModelAndView login(
@RequestParam(value = "error", required = false) String error,
@RequestParam(value = "logout", required = false) String logout) {
logger.info("------------------LoginController ---------------");
System.out.println("LoginController ");
ModelAndView model = new ModelAndView();
if (error != null) {
model.addObject("error", "Invalid username and password!");
}
if (logout != null) {
model.addObject("msg", "You've been logged out successfully.");
}
model.setViewName("login");
return model;
}
:今、/form.htmlを受け入れ、あなたのコントローラにはこの方法は、だから今、あなたがgottoそのマッピング値
/form.html
であり、それはGET
要求を受け入れ、あなたのコントローラクラスのメソッドを持って、ありません。/form'、 '.html'拡張子なし –それはうまくいきません。 –
何が起こっているのか疑問からは明らかではありません。あなたはフォーム提出で打っているURLをどのURLにリダイレクトしていますか?あなたが達成したいと思う行動は何ですか? –