質問編集履歴

1

コードを載せ忘れていました

2021/01/25 16:35

投稿

aaa11
aaa11

スコア14

test CHANGED
File without changes
test CHANGED
@@ -2,6 +2,286 @@
2
2
 
3
3
 
4
4
 
5
+ package dto;
6
+
7
+ import java.sql.Date;
8
+
9
+ import java.sql.Time;
10
+
11
+
12
+
13
+ public class WorkDto {
14
+
15
+
16
+
17
+ private int id;
18
+
19
+ private String userid;
20
+
21
+ private Date workday;
22
+
23
+ private Time attendacetimes;
24
+
25
+ private Time absencetimes;
26
+
27
+
28
+
29
+ public WorkDto (){
30
+
31
+ }
32
+
33
+
34
+
35
+ public WorkDto (String userid,Date workday,Time attendacetimes, Time absencetimes){
36
+
37
+ this.userid = userid;
38
+
39
+ this.workday = workday;
40
+
41
+ this.attendacetimes = attendacetimes;
42
+
43
+ this.absencetimes = absencetimes;
44
+
45
+ }
46
+
47
+
48
+
49
+ public int getid() {
50
+
51
+ return id;
52
+
53
+ }
54
+
55
+ public void setid(int id) {
56
+
57
+ this.id = id;
58
+
59
+ }
60
+
61
+ public String getUserid() {
62
+
63
+ return userid;
64
+
65
+ }
66
+
67
+ public void setUserid(String userid) {
68
+
69
+ this.userid = userid;
70
+
71
+ }
72
+
73
+ public Date getWorkday() {
74
+
75
+ return workday;
76
+
77
+ }
78
+
79
+ public void setWorkday(Date workday) {
80
+
81
+ this.workday = workday;
82
+
83
+ }
84
+
85
+ public Time getAttendacetimes() {
86
+
87
+ return attendacetimes;
88
+
89
+ }
90
+
91
+ public void setAttendacetimes(Time attendacetimes) {
92
+
93
+ this.attendacetimes = attendacetimes;
94
+
95
+ }
96
+
97
+ public Time getAbsencetimes() {
98
+
99
+ return absencetimes;
100
+
101
+ }
102
+
103
+ public void setgetAbsencetimes(Time absencetimes) {
104
+
105
+ this.absencetimes = absencetimes;
106
+
107
+ }
108
+
109
+ }
110
+
111
+
112
+
113
+ package servlet;
114
+
115
+
116
+
117
+ import java.io.IOException;
118
+
119
+ import java.sql.Time;
120
+
121
+
122
+
123
+ import javax.servlet.ServletException;
124
+
125
+ import javax.servlet.annotation.WebServlet;
126
+
127
+ import javax.servlet.http.HttpServlet;
128
+
129
+ import javax.servlet.http.HttpServletRequest;
130
+
131
+ import javax.servlet.http.HttpServletResponse;
132
+
133
+ import javax.servlet.http.HttpSession;
134
+
135
+
136
+
137
+ import dto.UserDto;
138
+
139
+ import dto.WorkDto;
140
+
141
+ import logic.WorkLogic;
142
+
143
+
144
+
145
+ /**
146
+
147
+ * Servlet implementation class AbsenceServlet
148
+
149
+ */
150
+
151
+ @WebServlet("/AbsenceServlet")
152
+
153
+ public class AbsenceServlet extends HttpServlet {
154
+
155
+ private static final long serialVersionUID = 1L;
156
+
157
+
158
+
159
+ /**
160
+
161
+ * @see HttpServlet#HttpServlet()
162
+
163
+ */
164
+
165
+ public AbsenceServlet() {
166
+
167
+ super();
168
+
169
+ // TODO Auto-generated constructor stub
170
+
171
+ }
172
+
173
+
174
+
175
+ /**
176
+
177
+ * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
178
+
179
+ */
180
+
181
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
182
+
183
+ // TODO Auto-generated method stub
184
+
185
+ doPost(request, response);
186
+
187
+ }
188
+
189
+
190
+
191
+ /**
192
+
193
+ * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
194
+
195
+ */
196
+
197
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
198
+
199
+ // TODO Auto-generated method stub
200
+
201
+ //レスポンス(出力データ)の文字コードを設定
202
+
203
+ response.setContentType("text/html;charset=UTF-8"); //文字コードをUTF-8で設定
204
+
205
+ //リクエスト(受信データ)の文字コードを設定
206
+
207
+ request.setCharacterEncoding("UTF-8"); //文字コードをUTF-8で設定
208
+
209
+ //セッションからユーザーデータを取得
210
+
211
+ HttpSession session = request.getSession();
212
+
213
+ UserDto userLoginSession = (UserDto)session.getAttribute("userlogin");
214
+
215
+ String userid = (String)session.getAttribute("userid"); //セッションからパラメータ取得(userid)
216
+
217
+ //java.util.Dateからjava.sql.Dateに変換
218
+
219
+ java.util.Date d = new java.util.Date();//現在日時を取得
220
+
221
+ java.sql.Date workday = new java.sql.Date(d.getTime());
222
+
223
+ //ログイン状態によって表示画面を振り分ける
224
+
225
+ if (userLoginSession != null) {
226
+
227
+ boolean succesFlg = true; //成功フラグ(true:成功/false:失敗)
228
+
229
+ WorkDto workdto = new WorkDto();
230
+
231
+ workdto.setUserid(userid);
232
+
233
+ workdto.setWorkday(workday);
234
+
235
+ workdto.setgetAbsencetimes(new Time(System.currentTimeMillis()));//現在時刻
236
+
237
+ //DBに登録
238
+
239
+ WorkLogic worklogic = new WorkLogic();
240
+
241
+ try {
242
+
243
+ succesFlg = worklogic.registAbsencetimeCheck(workdto);
244
+
245
+ } catch (Exception e) {
246
+
247
+ // TODO 自動生成された catch ブロック
248
+
249
+ e.printStackTrace();
250
+
251
+ }
252
+
253
+ //成功/失敗に応じて表示させる画面を振り分ける
254
+
255
+ if (succesFlg) {
256
+
257
+ //成功
258
+
259
+ request.getRequestDispatcher("/WEB-INF/jsp/absencetimes_success.jsp").forward(request, response);
260
+
261
+ } else {
262
+
263
+ //失敗した場合、エラー画面(error.jsp)を表示する
264
+
265
+ request.getRequestDispatcher("/WEB-INF/jsp/erro.jsp").forward(request, response);
266
+
267
+ // request.setAttribute("error", "再入力してください。");
268
+
269
+ }
270
+
271
+ }else {
272
+
273
+ //失敗:ログインNGとしてログイン画面へ転送
274
+
275
+ request.getRequestDispatcher("/WEB-INF/jsp/user_login.jsp").forward(request, response);
276
+
277
+ }
278
+
279
+ }
280
+
281
+ }
282
+
283
+
284
+
5
285
  package dao;
6
286
 
7
287