現在Springの勉強でバリデーションチェックをやっており、
エラーになったときにエラメッセージが表示されるようにはなりましたが、
URLが遷移先のものになってしまい、
さらにはトップ画面を表示する際に時間を取得する様にしていたのですが、
これが消えてしまっております。
試しに入力エラー時にはリダイレクトするようにしたら、
今度はエラーメッセージが表示されません。
どの様にすればよろしいでしょうか?
以下はソースになります。
index.jsp:トップ画面のjsp
html
1<body> 2 <h1>メニューを選択</h1> 3 4 <P>現在の時間です ${serverTime}.</P> 5 6 <spring:url value="/insert" var="action" /> 7 <form:form action="${action}" method="post" modelAttribute="testForm"> 8 <form:errors path="keyword" cssStyle="color:red" element="div" /> 9 送信:<form:input path="keyword" placeholder='ここに入力してください' /> 10 <input class="Button Radius5" id="IconList3" type="submit" value="送信" /> 11 </form:form> 12 <br> 13 <div class="Button Radius5" id="IconList3"> 14 <a href="/select">参照画面</a> 15 </div> 16 17</body>
homeController:トップ画面表示時のコントローラーです
java
1 2 /** 3 * トップページの表示 4 */ 5 @RequestMapping(value = "/", method = RequestMethod.GET) 6 public String home(Locale locale, Model model) { 7 logger.info("Welcome home! The client locale is {}.", locale); 8 9 Date date = new Date(); 10 DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); 11 12 String formattedDate = dateFormat.format(date); 13 14 model.addAttribute("serverTime", formattedDate); 15 model.addAttribute("testForm", new testForm()); 16 17 return "index"; 18 } 19
insertController:登録画面(作成中)の表示のコントローラーです
java
1 @ModelAttribute("testForm") 2 testForm setUpForm() { 3 return new testForm(); 4 } 5 6 /** 7 * 登録ページの表示 8 */ 9 @RequestMapping(value = "/insert", method = RequestMethod.POST) 10 public String home(@Valid testForm form, BindingResult result, Model model) { 11 if(result.hasErrors()) { 12 return "index"; 13 } 14 15 logger.debug("登録ページへの遷移です"); 16 String test = form.getKeyword(); 17 18 model.addAttribute("test", test); 19 20 return "insert"; 21 }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/05/22 05:05