質問編集履歴
3
コードを変更しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -113,33 +113,30 @@
|
|
113
113
|
<html lang="ja">
|
114
114
|
<head>
|
115
115
|
<%@ page language="java" contentType="text/html; charset=Windows-31J"
|
116
|
-
|
116
|
+
pageEncoding="Windows-31J"%>
|
117
117
|
<%@ page import="java.util.ArrayList"%>
|
118
|
+
</head>
|
118
119
|
|
119
120
|
|
120
|
-
<%
|
121
|
-
ArrayList<String> error = (ArrayList<String>) request.getAttribute("error");
|
122
|
-
if(error != null) {
|
123
|
-
for(int i = 0; i < error.size(); i++){
|
124
|
-
%>
|
125
|
-
<%=error.get(i) %>
|
126
|
-
<%
|
127
|
-
}
|
128
|
-
%>
|
129
|
-
<%
|
130
|
-
}
|
131
|
-
%>
|
132
|
-
|
133
|
-
|
134
121
|
<body>
|
135
|
-
|
122
|
+
<form action="/gyomuhokoku/LoginServlet" method="post">
|
136
|
-
|
123
|
+
<h1>ログイン</h1>
|
124
|
+
<%
|
125
|
+
ArrayList<String> error = (ArrayList<String>) request.getAttribute("error");
|
126
|
+
if (error != null) {
|
137
|
-
|
127
|
+
for (int i = 0; i < error.size(); i++) {
|
128
|
+
%>
|
129
|
+
<%=error.get(i)%>
|
130
|
+
<%
|
131
|
+
}
|
132
|
+
%>
|
133
|
+
<%
|
134
|
+
}
|
135
|
+
%>
|
138
|
-
|
136
|
+
ユーザーID:<input type="text" name="userId" id="notice-input-1"> <br>
|
139
|
-
|
137
|
+
パスワード:<input type="text" name="pass" id="notice-input-2"> <br>
|
140
|
-
|
138
|
+
<button type=submit>ログイン</button>
|
141
|
-
|
139
|
+
</form>
|
142
140
|
</body>
|
143
141
|
</html>
|
144
|
-
|
145
142
|
```
|
2
コメントをいただき、コードを変更しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,8 +6,10 @@
|
|
6
6
|
どなたかわかる方、教えていただけないでしょうか。→GETしたときは、表示されました。
|
7
7
|
しかし、POSTしてきたときにエラーになります。
|
8
8
|
|
9
|
-
org.apache.jasper.JasperException: An exception occurred processing [WEB-INF/Login.jsp] at line [12]と表示されます。
|
9
|
+
org.apache.jasper.JasperException: An exception occurred processing [WEB-INF/Login.jsp] at line [12]と表示されます。→コメント頂いて、エラーにはなりません。
|
10
10
|
|
11
|
+
でも、肝心のエラーが表示されません.......なぜなんでしょうか.....
|
12
|
+
|
11
13
|
```java
|
12
14
|
LoginServlet.java
|
13
15
|
|
@@ -115,16 +117,20 @@
|
|
115
117
|
<%@ page import="java.util.ArrayList"%>
|
116
118
|
|
117
119
|
|
118
|
-
|
119
120
|
<%
|
120
121
|
ArrayList<String> error = (ArrayList<String>) request.getAttribute("error");
|
122
|
+
if(error != null) {
|
121
|
-
|
123
|
+
for(int i = 0; i < error.size(); i++){
|
122
124
|
%>
|
123
|
-
|
125
|
+
<%=error.get(i) %>
|
124
126
|
<%
|
125
|
-
|
127
|
+
}
|
126
128
|
%>
|
129
|
+
<%
|
130
|
+
}
|
131
|
+
%>
|
127
132
|
|
133
|
+
|
128
134
|
<body>
|
129
135
|
<form action="/gyomuhokoku/LoginServlet" method="post">
|
130
136
|
<h1>ログイン</h1>
|
@@ -135,4 +141,5 @@
|
|
135
141
|
</form>
|
136
142
|
</body>
|
137
143
|
</html>
|
144
|
+
|
138
145
|
```
|
1
アドバイスを元にコードを変更しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,13 +3,14 @@
|
|
3
3
|
|
4
4
|
org.apache.jasper.JasperException: An exception occurred processing [/WEB-INF/Login.jsp]at line [12]
|
5
5
|
|
6
|
-
どなたかわかる方、教えていただけないでしょうか。
|
6
|
+
どなたかわかる方、教えていただけないでしょうか。→GETしたときは、表示されました。
|
7
|
+
しかし、POSTしてきたときにエラーになります。
|
7
8
|
|
9
|
+
org.apache.jasper.JasperException: An exception occurred processing [WEB-INF/Login.jsp] at line [12]と表示されます。
|
10
|
+
|
8
11
|
```java
|
9
|
-
|
12
|
+
LoginServlet.java
|
10
13
|
|
11
|
-
|
12
|
-
|
13
14
|
package servlet;
|
14
15
|
|
15
16
|
import java.io.IOException;
|
@@ -36,6 +37,7 @@
|
|
36
37
|
|
37
38
|
|
38
39
|
ArrayList<String> error = new ArrayList<>();
|
40
|
+
request.setAttribute("error", error);
|
39
41
|
error.add("");
|
40
42
|
|
41
43
|
|
@@ -59,17 +61,51 @@
|
|
59
61
|
|
60
62
|
if(userId == null) {
|
61
63
|
error.add("ログインIDを入力してください。");
|
64
|
+
request.setAttribute("error", error);
|
62
65
|
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/Login.jsp");
|
63
66
|
dispatcher.forward(request, response);
|
64
67
|
}else if(pass == null){
|
65
68
|
error.add("パスワードを入力してください。");
|
69
|
+
request.setAttribute("error", error);
|
66
70
|
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/Login.jsp");
|
67
71
|
dispatcher.forward(request, response);
|
68
72
|
}
|
73
|
+
|
74
|
+
//ログイン処理の実行
|
75
|
+
Login rs = new Login();
|
76
|
+
rs.setUserId(userId);
|
77
|
+
rs.setPass(pass);
|
78
|
+
AccountLogic bo = new AccountLogic();
|
79
|
+
boolean result = bo.execute(rs);
|
80
|
+
|
81
|
+
//ログインの成否によって処理を分岐
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
if (result) { //ログイン成功時
|
86
|
+
|
87
|
+
//セッションスコープにユーザーIDを保存
|
88
|
+
HttpSession session = request.getSession();
|
89
|
+
session.setAttribute("userId", userId);
|
90
|
+
|
91
|
+
//フォワード
|
92
|
+
RequestDispatcher dispatcher = request.getRequestDispatcher("/ListScreen");
|
93
|
+
dispatcher.forward(request, response);
|
94
|
+
} else {
|
95
|
+
//ログイン失敗時
|
96
|
+
//
|
97
|
+
|
98
|
+
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/Login.jsp");
|
99
|
+
dispatcher.forward(request, response);
|
100
|
+
|
101
|
+
}
|
102
|
+
}
|
103
|
+
}
|
104
|
+
|
69
105
|
```
|
70
106
|
|
71
107
|
```java
|
72
|
-
|
108
|
+
Login.jsp
|
73
109
|
|
74
110
|
<!DOCTYPE HTML>
|
75
111
|
<html lang="ja">
|
@@ -90,10 +126,11 @@
|
|
90
126
|
%>
|
91
127
|
|
92
128
|
<body>
|
93
|
-
<form action="/gyomuhokoku/LoginServlet">
|
129
|
+
<form action="/gyomuhokoku/LoginServlet" method="post">
|
94
130
|
<h1>ログイン</h1>
|
131
|
+
<span id="input_error"></span>
|
95
|
-
ユーザーID:<input type="text" name="userId"> <br>
|
132
|
+
ユーザーID:<input type="text" name="userId" id="notice-input-1"> <br>
|
96
|
-
パスワード:<input type="text" name="pass"> <br>
|
133
|
+
パスワード:<input type="text" name="pass" id="notice-input-2"> <br>
|
97
134
|
<button type=submit>ログイン</button>
|
98
135
|
</form>
|
99
136
|
</body>
|