Repository navigation
Expand file tree
/
Copy path3_05_HW2_optional_select_user.patch
More file actions
69 lines (65 loc) · 2.45 KB
/
Copy path3_05_HW2_optional_select_user.patch
File metadata and controls
69 lines (65 loc) · 2.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Index: src/main/java/ru/javawebinar/topjava/web/UserServlet.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/ru/javawebinar/topjava/web/UserServlet.java (date 1531049646000)
+++ src/main/java/ru/javawebinar/topjava/web/UserServlet.java (date 1531051687862)
@@ -13,6 +13,13 @@
public class UserServlet extends HttpServlet {
private static final Logger log = getLogger(UserServlet.class);
+ @Override
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ int userId = Integer.parseInt(request.getParameter("userId"));
+ SecurityUtil.setAuthUserId(userId);
+ response.sendRedirect("meals");
+ }
+
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
log.debug("forward to users");
Index: src/main/java/ru/javawebinar/topjava/web/SecurityUtil.java
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/java/ru/javawebinar/topjava/web/SecurityUtil.java (date 1531049646000)
+++ src/main/java/ru/javawebinar/topjava/web/SecurityUtil.java (date 1531051687855)
@@ -4,8 +4,14 @@
public class SecurityUtil {
+ private static int id = 1;
+
public static int authUserId() {
- return 1;
+ return id;
+ }
+
+ public static void setAuthUserId(int id) {
+ SecurityUtil.id = id;
}
public static int authUserCaloriesPerDay() {
Index: src/main/webapp/index.html
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- src/main/webapp/index.html (date 1531049646000)
+++ src/main/webapp/index.html (date 1531051525032)
@@ -6,9 +6,13 @@
<body>
<h3>Проект <a href="https://github.com/JavaWebinar/topjava" target="_blank">Java Enterprise (Topjava)</a></h3>
<hr>
-<ul>
- <li><a href="users">Users</a></li>
- <li><a href="meals">Meals</a></li>
-</ul>
+<form method="post" action="users">
+ <b>Meals of </b>
+ <select name="userId">
+ <option value="1">User</option>
+ <option value="2">Admin</option>
+ </select>
+ <button type="submit">Select</button>
+</form>
</body>
</html>