質問編集履歴
1
(編集)ソースコード箇所、[コード]に修正しました。(追記)ツールのバージョンをわかる範囲ですが追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -190,6 +190,82 @@
|
|
190
190
|
|
191
191
|
```
|
192
192
|
|
193
|
+
```
|
194
|
+
|
195
|
+
@WebServlet("/employees/index")
|
196
|
+
|
197
|
+
public class EmployeeIndexServlet extends HttpServlet {
|
198
|
+
|
199
|
+
private static final long serialVersionUID = 1L;
|
200
|
+
|
201
|
+
|
202
|
+
|
203
|
+
public EmployeeIndexServlet() {
|
204
|
+
|
205
|
+
super();
|
206
|
+
|
207
|
+
// TODO Auto-generated constructor stub
|
208
|
+
|
209
|
+
}
|
210
|
+
|
211
|
+
|
212
|
+
|
213
|
+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
214
|
+
|
215
|
+
EntityManager em = DBUtil.createEntityManager();
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
int page = 1;
|
220
|
+
|
221
|
+
try{
|
222
|
+
|
223
|
+
page = Integer.parseInt(request.getParameter("page"));
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
} catch(NumberFormatException e) {}
|
228
|
+
|
229
|
+
List<Employee> employees = em.createNamedQuery("getAllEmployees", Employee.class).setFirstResult(15 * (page - 1)).setMaxResults(15).getResultList();
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
long employees_count = (long)em.createNamedQuery("getEmployeesCount", Long.class).getSingleResult();
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
em.close();
|
238
|
+
|
239
|
+
|
240
|
+
|
241
|
+
request.setAttribute("employees", employees);
|
242
|
+
|
243
|
+
request.setAttribute("employees_count", employees_count);
|
244
|
+
|
245
|
+
request.setAttribute("page", page);
|
246
|
+
|
247
|
+
if(request.getSession().getAttribute("flush") != null){
|
248
|
+
|
249
|
+
request.setAttribute("flush", request.getSession().getAttribute("flush"));
|
250
|
+
|
251
|
+
request.getSession().removeAttribute("flush");
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/views/employees/index.jsp");
|
258
|
+
|
259
|
+
rd.forward(request, response);
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
```
|
268
|
+
|
193
269
|
|
194
270
|
|
195
271
|
### 試したこと
|
@@ -204,78 +280,6 @@
|
|
204
280
|
|
205
281
|
|
206
282
|
|
207
|
-
コードです
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
@WebServlet("/employees/index")
|
212
|
-
|
213
|
-
public class EmployeeIndexServlet extends HttpServlet {
|
214
|
-
|
215
|
-
private static final long serialVersionUID = 1L;
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
public EmployeeIndexServlet() {
|
220
|
-
|
221
|
-
super();
|
222
|
-
|
223
|
-
// TODO Auto-generated constructor stub
|
224
|
-
|
225
|
-
}
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
230
|
-
|
231
|
-
EntityManager em = DBUtil.createEntityManager();
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
int page = 1;
|
236
|
-
|
237
|
-
|
283
|
+
(追記)
|
238
|
-
|
239
|
-
|
284
|
+
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
} catch(NumberFormatException e) {}
|
244
|
-
|
245
|
-
List<Employee> employees = em.createNamedQuery("getAllEmployees", Employee.class).setFirstResult(15 * (page - 1)).setMaxResults(15).getResultList();
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
long employees_count = (long)em.createNamedQuery("getEmployeesCount", Long.class).getSingleResult();
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
em.close();
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
request.setAttribute("employees", employees);
|
258
|
-
|
259
|
-
request.setAttribute("employees_count", employees_count);
|
260
|
-
|
261
|
-
request.setAttribute("page", page);
|
262
|
-
|
263
|
-
if(request.getSession().getAttribute("flush") != null){
|
264
|
-
|
265
|
-
request.setAttribute("flush", request.getSession().getAttribute("flush"));
|
266
|
-
|
267
|
-
request.getSession().removeAttribute("flush");
|
268
|
-
|
269
|
-
}
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/views/employees/index.jsp");
|
274
|
-
|
275
|
-
|
285
|
+
Java8, Hibernate5, Tomcat8
|
276
|
-
|
277
|
-
}
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
}
|