質問編集履歴

7

コードの修正

2022/08/01 06:07

投稿

RYU
RYU

スコア13

test CHANGED
File without changes
test CHANGED
@@ -94,7 +94,7 @@
94
94
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
95
95
  try {
96
96
  String sql = "select * from mst_user user join mst_staff staff on user.staff_kbn = staff.staff_kbn where user.user_id = ? and user.user_pass = ?;";
97
- Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/imada?serverTimezone=Asia/Tokyo","root","*****");
97
+ Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/imada?serverTimezone=Asia/Tokyo","root","ryugo3849");
98
98
  PreparedStatement ps = connection.prepareStatement(sql);
99
99
 
100
100
  LoginAuthentication authen = new LoginAuthentication();
@@ -118,7 +118,8 @@
118
118
  request.getSession().setAttribute("login", users.get(0));
119
119
  getServletContext().getRequestDispatcher("/menu.jsp").forward(request,response);
120
120
  }
121
+
121
-
122
+ //変更箇所
122
123
  var user = users.get(0);
123
124
 
124
125
  //データベースから取得したgetStaff_descの値がauthorityと同じ(商品部)だったらuser_authorityを1にする。
@@ -159,6 +160,8 @@
159
160
  return ret;
160
161
  }
161
162
  }
163
+
164
+
162
165
  ```
163
166
 
164
167
  ---
@@ -187,7 +190,7 @@
187
190
  <ul>
188
191
  <li><a href="sales_detail_check.jsp">売上実績参照画面</a></li>
189
192
      //user_authorityが1(商品部ユーザーだったらリンクを表示する)
190
- <c:if test="${authority[0].user_authority == 1 }">
193
+ <c:if test="${authority.user_authority == 1 }">
191
194
  <li><a href="#">ユーザー登録画面</a></li>
192
195
      </c:if>
193
196
  <li><a href="#">売上実績サマリ確認画面</a></li>

6

コードの修正

2022/08/01 05:54

投稿

RYU
RYU

スコア13

test CHANGED
File without changes
test CHANGED
@@ -105,28 +105,30 @@
105
105
  ps.setString(2,authen.getUser_pass());
106
106
 
107
107
  ResultSet rs = ps.executeQuery();
108
- List<LoginAuthentication> user = toUserList(rs);
108
+ List<LoginAuthentication> users = toUserList(rs);
109
-
109
+
110
- if (user.isEmpty() == true) {
110
+ if (users.isEmpty() == true) {
111
111
  List<String> messages = new ArrayList<String>();
112
112
  messages.add("ログインに失敗しました。");
113
113
  request.setAttribute("errorMessages", messages);
114
114
  getServletContext().getRequestDispatcher("/index.jsp").forward(request,response);
115
- } else if (2 <= user.size()) {
115
+ } else if (2 <= users.size()) {
116
116
  throw new IllegalStateException("2 <= userList.size()");
117
117
  } else {
118
- request.getSession().setAttribute("login", user.get(0));
118
+ request.getSession().setAttribute("login", users.get(0));
119
119
  getServletContext().getRequestDispatcher("/menu.jsp").forward(request,response);
120
120
  }
121
121
 
122
+ var user = users.get(0);
123
+
122
124
  //データベースから取得したgetStaff_descの値がauthorityと同じ(商品部)だったらuser_authorityを1にする。
123
125
  //LoginAuthenticationで定義。
124
- if(user.get(0).getStaff_desc().equals(user.get(0).authority)){
126
+ if(user.getStaff_desc().equals(user.authority)){
125
- user.get(0).user_authority = 1;
127
+ user.user_authority = 1;
126
128
  request.setAttribute("authority", user);
127
129
  getServletContext().getRequestDispatcher("/menu.jsp").forward(request,response);
128
130
  }else {
129
- user.get(0).user_authority = 0;
131
+ user.user_authority = 0;
130
132
  request.setAttribute("authority", user);
131
133
  getServletContext().getRequestDispatcher("/menu.jsp").forward(request,response);
132
134
  }
@@ -185,7 +187,7 @@
185
187
  <ul>
186
188
  <li><a href="sales_detail_check.jsp">売上実績参照画面</a></li>
187
189
      //user_authorityが1(商品部ユーザーだったらリンクを表示する)
188
- <c:if test="${authority.user_authority == 1 }">
190
+ <c:if test="${authority[0].user_authority == 1 }">
189
191
  <li><a href="#">ユーザー登録画面</a></li>
190
192
      </c:if>
191
193
  <li><a href="#">売上実績サマリ確認画面</a></li>

5

内容の修正

2022/08/01 05:21

投稿

RYU
RYU

スコア13

test CHANGED
File without changes
test CHANGED
@@ -32,7 +32,7 @@
32
32
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-08-01/84ba4263-add1-40df-9f0c-a0db882c7fed.png)
33
33
  ---
34
34
 
35
- MySQLのMST_STAFFテーブル
35
+ MST_USERテーブルとMST_STAFFテーブルを結合し取得(LoginServlet.javaの27行目)
36
36
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-08-01/ce849f3f-cb23-4b9a-b254-802eb832fe36.png)
37
37
  ---
38
38
 
@@ -94,7 +94,7 @@
94
94
  protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
95
95
  try {
96
96
  String sql = "select * from mst_user user join mst_staff staff on user.staff_kbn = staff.staff_kbn where user.user_id = ? and user.user_pass = ?;";
97
- Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/imada?serverTimezone=Asia/Tokyo","root","ryugo3849");
97
+ Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/imada?serverTimezone=Asia/Tokyo","root","*****");
98
98
  PreparedStatement ps = connection.prepareStatement(sql);
99
99
 
100
100
  LoginAuthentication authen = new LoginAuthentication();

4

写真の追加

2022/08/01 03:09

投稿

RYU
RYU

スコア13

test CHANGED
File without changes
test CHANGED
@@ -11,7 +11,7 @@
11
11
  ログインID : user3 → 商品部スタッフ(munu.jspの"ユーザー登録画面"のリンクを表示)
12
12
 
13
13
  ### 発生している問題の詳細・エラーメッセージ
14
- 本来のメニュー画面 - user3 (index.jsp)
14
+ 本来のメニュー画面 - user3 (menu.jsp)
15
15
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-08-01/8ceb2b25-0d76-405e-9dbe-43fee89e3abd.png)
16
16
  ---
17
17
 
@@ -32,7 +32,9 @@
32
32
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-08-01/84ba4263-add1-40df-9f0c-a0db882c7fed.png)
33
33
  ---
34
34
 
35
-
35
+ MySQLのMST_STAFFテーブル
36
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-08-01/ce849f3f-cb23-4b9a-b254-802eb832fe36.png)
37
+ ---
36
38
 
37
39
  ### 該当のソースコード
38
40
 

3

画像の修正

2022/08/01 03:05

投稿

RYU
RYU

スコア13

test CHANGED
File without changes
test CHANGED
@@ -11,8 +11,8 @@
11
11
  ログインID : user3 → 商品部スタッフ(munu.jspの"ユーザー登録画面"のリンクを表示)
12
12
 
13
13
  ### 発生している問題の詳細・エラーメッセージ
14
- 本来のメニュー画面 - user1 (index.jsp)
14
+ 本来のメニュー画面 - user3 (index.jsp)
15
- ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-08-01/7e01579b-7814-448b-9c44-03291f836da7.png)
15
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-08-01/8ceb2b25-0d76-405e-9dbe-43fee89e3abd.png)
16
16
  ---
17
17
 
18
18
  ログイン画面 - user1 (index.jsp)

2

文章の修正

2022/08/01 03:03

投稿

RYU
RYU

スコア13

test CHANGED
File without changes
test CHANGED
@@ -1,14 +1,14 @@
1
1
 
2
2
  ### 質問内容
3
3
 
4
- 現在、簡易的なログイン証認機能の実装をしているのですが、ユーザの権限によって表示させる内容を変える処理の実装に困っています。具体的な状況を説明しますと、まず、ユーザーにはSTAFF_DESCの”店舗”と”商品部”の二種類のユーザーがMySQLのMST_STAFFテーブルで定義されています。今回は、ログインしたユーザーをSTAFF_DESCの内容(店舗スタッフが商品部スタッフ)によってmenu.jspにある"ユーザー登録画面"のリンクを表示/非表示にしたいです。その為、menu.jspの方に<c:if>で条件がTrueだったらリンクを表示させるという処理を書き、LoginServlet.javaの方に新しいSQL文、新しい条件式を追記したのですが、<c:if>がTrueになっていないのか、店舗スタッフの場合でも"ユーザー登録画面"のリンクが表示されなくて困っています。
4
+ 現在、簡易的なログイン証認機能の実装をしているのですが、ユーザの権限によって表示させる内容を変える処理の実装に困っています。具体的な状況を説明しますと、まず、ユーザーにはSTAFF_DESCの”店舗”と”商品部”の二種類のユーザーがMySQLのMST_STAFFテーブルで定義されています。今回は、ログインしたユーザーをSTAFF_DESCの内容(店舗スタッフが商品部スタッフ)によってmenu.jspにある"ユーザー登録画面"のリンクを表示/非表示にしたいです。その為、menu.jspの方に<c:if>で条件がTrueだったらリンクを表示させるという処理を書き、LoginServlet.javaの方に新しいSQL文、新しい条件式を追記したのですが、<c:if>がTrueになっていないのか、商品部スタッフの場合でも"ユーザー登録画面"のリンクが表示されなくて困っています。
5
5
  どこをどのようになおせばいいのか分からなかったので、また質問させて頂くことにしました。
6
6
  ご教授頂ければ幸いです。宜しくお願いします。
7
7
 
8
8
  スタッフ区分を判断する処理 → LoginAuthentication.javaの"user_authority"が"0"なら店舗スタッフ、"1"なら商品部スタッフと判断する条件式をLoginServlet.javaの53行目に記述。
9
9
 
10
- ログインID : user1 → 店舗スタッフ(munu.jspの"ユーザー登録画面"のリンクを表示)
10
+ ログインID : user1 → 店舗スタッフ(munu.jspの"ユーザー登録画面"のリンクを表示)
11
- ログインID : user3 → 商品部スタッフ(munu.jspの"ユーザー登録画面"のリンクを表示)
11
+ ログインID : user3 → 商品部スタッフ(munu.jspの"ユーザー登録画面"のリンクを表示)
12
12
 
13
13
  ### 発生している問題の詳細・エラーメッセージ
14
14
  本来のメニュー画面 - user1 (index.jsp)
@@ -182,6 +182,7 @@
182
182
  <h3>メニュー画面</h3>
183
183
  <ul>
184
184
  <li><a href="sales_detail_check.jsp">売上実績参照画面</a></li>
185
+     //user_authorityが1(商品部ユーザーだったらリンクを表示する)
185
186
  <c:if test="${authority.user_authority == 1 }">
186
187
  <li><a href="#">ユーザー登録画面</a></li>
187
188
      </c:if>

1

追記

2022/08/01 02:58

投稿

RYU
RYU

スコア13

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,7 @@
8
8
  スタッフ区分を判断する処理 → LoginAuthentication.javaの"user_authority"が"0"なら店舗スタッフ、"1"なら商品部スタッフと判断する条件式をLoginServlet.javaの53行目に記述。
9
9
 
10
10
  ログインID : user1 → 店舗スタッフ(munu.jspの"ユーザー登録画面"のリンクを表示)
11
-        user3 → 商品部スタッフ(munu.jspの"ユーザー登録画面"のリンクを非表示)
11
+ ログインID : user3 → 商品部スタッフ(munu.jspの"ユーザー登録画面"のリンクを非表示)
12
12
 
13
13
  ### 発生している問題の詳細・エラーメッセージ
14
14
  本来のメニュー画面 - user1 (index.jsp)