teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

1

リクエスト・ディスパッチャの遷移先指定を修正

2020/11/19 04:56

投稿

A-pZ
A-pZ

スコア12011

answer CHANGED
@@ -1,20 +1,9 @@
1
- ```java
2
- if(errorCheck.hasErrors()) {
3
- request.setAttribute("errors", errorCheck.getErrorList());
4
- RequestDispatcher dispatch = request.getRequestDispatcher("http://localhost:8080/shopinfo/");
5
- dispatch.forward(request, response);
6
- }
7
-
8
- // この後に処理が続いている場合、実行される。
9
-
10
- ```
11
-
12
1
  リクエストディスパッチャ(RequestDispatcher)でforwardやredirectを指定した後に、また処理が記述されている場合は、処理が継続します。適切なタイミングでreturn; をしてください。
13
2
 
14
3
  ```java
15
4
  if(errorCheck.hasErrors()) {
16
5
  request.setAttribute("errors", errorCheck.getErrorList());
17
- RequestDispatcher dispatch = request.getRequestDispatcher("http://localhost:8080/shopinfo/");
6
+ RequestDispatcher dispatch = request.getRequestDispatcher("遷移先のJSP");
18
7
  dispatch.forward(request, response);
19
8
  return;
20
9
  }