質問編集履歴
3
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,8 +7,6 @@
|
|
7
7
|
<c:ifを使ってコードを書いてみたのですが、
|
8
8
|
期待した結果が得られなかったので、<c:if文の部分のコードを記載しますのでアドバイスを頂きたいです。
|
9
9
|
###追記内容
|
10
|
-
自分で試した内容について参考にさせて頂いたURL
|
11
|
-
http://struts.wasureppoi.com/jstl/02_if.html
|
12
10
|

|
13
11
|
JSP、以前の内容から色々書き直しているのでコード修正しました。
|
14
12
|
### 試した内容
|
@@ -46,18 +44,18 @@
|
|
46
44
|
</tr>
|
47
45
|
<c:if test="${flg}">
|
48
46
|
<tr>
|
49
|
-
<td class ="area"
|
47
|
+
<td class ="area"><c:out value="${truck.m_wholesale_area}"></c:out></td>
|
50
|
-
<td class ="area"
|
48
|
+
<td class ="area"><c:out value="${truck.stack_area}"></c:out></td>
|
51
|
-
<td class ="area"
|
49
|
+
<td class ="area"><c:out value="${truck.wholesale_area}"></c:out></td>
|
52
|
-
<td class ="area"
|
50
|
+
<td class ="area"><c:out value="${truck.e_stack_area}"></c:out></td>
|
53
51
|
</tr>
|
54
52
|
</c:if>
|
55
53
|
<c:if test="${!flg}">
|
56
54
|
<tr>
|
57
|
-
<td class ="area"
|
55
|
+
<td class ="area"><c:out value="${truck.m_wholesale_area}"></c:out></td>
|
58
|
-
<td class ="area"
|
56
|
+
<td class ="area"><c:out value="${truck.stack_area}"></c:out></td>
|
59
|
-
<td class ="area"
|
57
|
+
<td class ="area"><c:out value="${truck.wholesale_area}"></c:out></td>
|
60
|
-
<td class ="area"
|
58
|
+
<td class ="area"><c:out value="${truck.e_stack_area}"></c:out></td>
|
61
59
|
</tr>
|
62
60
|
</c:if>
|
63
61
|
<tr>
|
@@ -80,30 +78,6 @@
|
|
80
78
|
```
|
81
79
|
**DispatchIndexServlet.java**
|
82
80
|
```Java
|
83
|
-
import java.io.IOException;
|
84
|
-
import java.util.List;
|
85
|
-
|
86
|
-
import javax.persistence.EntityManager;
|
87
|
-
import javax.servlet.RequestDispatcher;
|
88
|
-
import javax.servlet.ServletException;
|
89
|
-
import javax.servlet.annotation.WebServlet;
|
90
|
-
import javax.servlet.http.HttpServlet;
|
91
|
-
import javax.servlet.http.HttpServletRequest;
|
92
|
-
import javax.servlet.http.HttpServletResponse;
|
93
|
-
|
94
|
-
import models.Trucks;
|
95
|
-
import utils.DBUtil;
|
96
|
-
|
97
|
-
|
98
|
-
@WebServlet("/dispatch/index")
|
99
|
-
public class DispatchIndexServlet extends HttpServlet {
|
100
|
-
private static final long serialVersionUID = 1L;
|
101
|
-
|
102
|
-
|
103
|
-
public DispatchIndexServlet() {
|
104
|
-
super();
|
105
|
-
}
|
106
|
-
|
107
81
|
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
108
82
|
EntityManager em = DBUtil.createEntityManager();
|
109
83
|
|
@@ -130,7 +104,7 @@
|
|
130
104
|
}
|
131
105
|
|
132
106
|
```
|
133
|
-
|
107
|
+
_form.jsp
|
134
108
|
```JSP
|
135
109
|
<p>
|
136
110
|
<form method="GET" action = "DispatchCreateServlet.java">
|
@@ -142,4 +116,100 @@
|
|
142
116
|
<button type="submit">登録</button>
|
143
117
|
</form>
|
144
118
|
|
119
|
+
```
|
120
|
+
DispatchCreateServlet.java
|
121
|
+
```Java
|
122
|
+
|
123
|
+
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
124
|
+
String _token = (String)request.getParameter("_token");
|
125
|
+
if(_token != null && _token.equals(request.getSession().getId())) {
|
126
|
+
EntityManager em = DBUtil.createEntityManager();
|
127
|
+
|
128
|
+
Trucks t = new Trucks();
|
129
|
+
|
130
|
+
String sa_select = request.getParameter("sa_select");
|
131
|
+
String sa_text = request.getParameter("sa_text");
|
132
|
+
String stack_area = sa_select + sa_text;
|
133
|
+
String wa_select = request.getParameter("wa_select");
|
134
|
+
String wa_text = request.getParameter("wa_text");
|
135
|
+
String wholesale_area = wa_select + wa_text;
|
136
|
+
String office_name = request.getParameter("office_name");
|
137
|
+
String wa_time = request.getParameter("wa_time");
|
138
|
+
String sa_time = request.getParameter("sa_time");
|
139
|
+
String wa_time2 = request.getParameter("wa_time2");
|
140
|
+
String sa_time2 = request.getParameter("sa_time2");
|
141
|
+
String es_select = request.getParameter("es_select");
|
142
|
+
String es_text = request.getParameter("es_text");
|
143
|
+
String e_stack_area = es_select +es_text;
|
144
|
+
String mw_time = request.getParameter("mw_time");
|
145
|
+
String es_time = request.getParameter("es_time");
|
146
|
+
String mw_select = request.getParameter("mw_select");
|
147
|
+
String mw_text = request.getParameter("mw_text");
|
148
|
+
String m_wholesale_area = mw_select + mw_text;
|
149
|
+
String sa_select2 = request.getParameter("sa_select2");
|
150
|
+
String sa_text2 = request.getParameter("sa_text2");
|
151
|
+
String stack_area2 = sa_select2 + sa_text2;
|
152
|
+
String wa_select2 = request.getParameter("wa_select2");
|
153
|
+
String wa_text2 = request.getParameter("wa_text2");
|
154
|
+
String wholesale_area2 = wa_select2 + wa_text2;
|
155
|
+
|
156
|
+
Date task_date = new Date(System.currentTimeMillis());
|
157
|
+
String rd_str = request.getParameter("task_date");
|
158
|
+
if(rd_str != null && !rd_str.equals("")){
|
159
|
+
task_date = Date.valueOf(request.getParameter("task_date"));
|
160
|
+
|
161
|
+
}
|
162
|
+
t.setTask_date(task_date);
|
163
|
+
t.setStack_area(stack_area);
|
164
|
+
t.setWholesale_area(wholesale_area);
|
165
|
+
t.setOffice_name(office_name);
|
166
|
+
t.setWa_time(wa_time);
|
167
|
+
t.setSa_time(sa_time);
|
168
|
+
t.setWa_time2(wa_time2);
|
169
|
+
t.setSa_time2(sa_time2);
|
170
|
+
t.setM_wholesale_area(m_wholesale_area);
|
171
|
+
t.setE_stack_area(e_stack_area);
|
172
|
+
t.setMw_time(mw_time);
|
173
|
+
t.setEs_time(es_time);
|
174
|
+
t.setStack_area2(stack_area2);
|
175
|
+
t.setWholesale_area2(wholesale_area2);
|
176
|
+
|
177
|
+
List<String> errors = DispatchValidator.validate(t);
|
178
|
+
if(errors.size() > 0) {
|
179
|
+
em.close();
|
180
|
+
|
181
|
+
request.setAttribute("errors", errors);
|
182
|
+
request.setAttribute("_token", request.getSession().getId());
|
183
|
+
request.setAttribute("stack_area",stack_area);
|
184
|
+
request.setAttribute("wholesale_area",wholesale_area);
|
185
|
+
request.setAttribute("office_name",office_name);
|
186
|
+
request.setAttribute("wa_time",wa_time);
|
187
|
+
request.setAttribute("sa_time",sa_time);
|
188
|
+
request.setAttribute("wa_time2",wa_time2);
|
189
|
+
request.setAttribute("sa_time2",sa_time2);
|
190
|
+
request.setAttribute("e_stack_area",e_stack_area);
|
191
|
+
request.setAttribute("m_wholesale_area",m_wholesale_area);
|
192
|
+
request.setAttribute("mw_time",mw_time);
|
193
|
+
request.setAttribute("es_time",es_time);
|
194
|
+
request.setAttribute("stack_area2",stack_area2);
|
195
|
+
request.setAttribute("wholesale_area2",wholesale_area2);
|
196
|
+
|
197
|
+
RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/views/dispatch/new.jsp");
|
198
|
+
rd.forward(request, response);
|
199
|
+
|
200
|
+
} else {
|
201
|
+
em.getTransaction().begin();
|
202
|
+
em.persist(t);
|
203
|
+
em.getTransaction().commit();
|
204
|
+
em.close();
|
205
|
+
request.getSession().setAttribute("flush", "登録が完了しました。");
|
206
|
+
|
207
|
+
response.sendRedirect(request.getContextPath() + "/dispatch/index");
|
208
|
+
}
|
209
|
+
|
210
|
+
}
|
211
|
+
}
|
212
|
+
}
|
213
|
+
|
214
|
+
|
145
215
|
```
|
2
追記・修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,25 +6,140 @@
|
|
6
6
|
そのため、formで入力した日付と一致する日付の場所に情報を表示させようと思い、
|
7
7
|
<c:ifを使ってコードを書いてみたのですが、
|
8
8
|
期待した結果が得られなかったので、<c:if文の部分のコードを記載しますのでアドバイスを頂きたいです。
|
9
|
-
###追記
|
9
|
+
###追記内容
|
10
10
|
自分で試した内容について参考にさせて頂いたURL
|
11
11
|
http://struts.wasureppoi.com/jstl/02_if.html
|
12
|
+

|
13
|
+
JSP、以前の内容から色々書き直しているのでコード修正しました。
|
12
14
|
### 試した内容
|
15
|
+
**index.jsp**
|
16
|
+
```JSP
|
17
|
+
<div class="Truck_table_wrapper">
|
18
|
+
<table class="Truck_table">
|
19
|
+
<thead>
|
20
|
+
<tr>
|
21
|
+
<th class="space1" rowspan="2" colspan="4"></th>
|
22
|
+
<c:forEach begin="1" end="31" varStatus="stts">
|
23
|
+
<th class="date" colspan="4">1月<c:out value="${stts.count}"></c:out>日</th></c:forEach>
|
24
|
+
</tr>
|
25
|
+
<tr>
|
26
|
+
<c:forEach begin="1" end="31">
|
27
|
+
<th class="task_type">宵積卸地</th>
|
28
|
+
<th class="task_type">積地</th>
|
29
|
+
<th class="task_type">卸地</th>
|
30
|
+
<th class="task_type">宵積</th>
|
31
|
+
</c:forEach>
|
32
|
+
</tr>
|
33
|
+
</thead>
|
34
|
+
<c:if test="${value == null}" var="flg">
|
35
|
+
<c:forEach var="truck" items="${trucks}" varStatus="status">
|
36
|
+
<tbody>
|
37
|
+
<tr>
|
38
|
+
<td class="office_name" rowspan="4"><c:out value="${truck.office_name}"></c:out></td>
|
39
|
+
<td class ="truck_code" colspan="2" rowspan="4"><c:out value="${truck.truck_code}"></c:out></td>
|
40
|
+
<td class ="truck_type" rowspan="4"><c:out value="${truck.truck_type}"></c:out></td>
|
13
41
|
|
42
|
+
<td class ="time"><c:out value="${truck.mw_time}"></c:out></td>
|
43
|
+
<td class ="time"><c:out value="${truck.sa_time}"></c:out></td>
|
44
|
+
<td class ="time"><c:out value="${truck.wa_time}"></c:out></td>
|
45
|
+
<td class ="time"><c:out value="${truck.es_time}"></c:out></td>
|
46
|
+
</tr>
|
47
|
+
<c:if test="${flg}">
|
48
|
+
<tr>
|
49
|
+
<td class ="area" id="1"><c:out value="${truck.m_wholesale_area}"></c:out></td>
|
50
|
+
<td class ="area" id="1"><c:out value="${truck.stack_area}"></c:out></td>
|
51
|
+
<td class ="area" id="1"><c:out value="${truck.wholesale_area}"></c:out></td>
|
52
|
+
<td class ="area" id="1"><c:out value="${truck.e_stack_area}"></c:out></td>
|
53
|
+
</tr>
|
54
|
+
</c:if>
|
55
|
+
<c:if test="${!flg}">
|
56
|
+
<tr>
|
57
|
+
<td class ="area" id="2"><c:out value="${truck.m_wholesale_area}"></c:out></td>
|
58
|
+
<td class ="area" id="2"><c:out value="${truck.stack_area}"></c:out></td>
|
59
|
+
<td class ="area" id="2"><c:out value="${truck.wholesale_area}"></c:out></td>
|
60
|
+
<td class ="area" id="2"><c:out value="${truck.e_stack_area}"></c:out></td>
|
61
|
+
</tr>
|
62
|
+
</c:if>
|
63
|
+
<tr>
|
64
|
+
<td class ="time"></td>
|
65
|
+
<td class ="time"><c:out value="${truck.sa_time2}"></c:out></td>
|
66
|
+
<td class ="time"><c:out value="${truck.wa_time2}"></c:out></td>
|
67
|
+
<td class ="time"></td>
|
68
|
+
</tr>
|
69
|
+
<tr>
|
70
|
+
<td class ="area" id="3">ボタン</td>
|
71
|
+
<td class ="area" id="3"><c:out value="${truck.stack_area2}"></c:out></td>
|
72
|
+
<td class ="area" id="3"><c:out value="${truck.wholesale_area2}"></c:out></td>
|
73
|
+
<td class ="area" id="3">ボタン</td>
|
74
|
+
</tr>
|
75
|
+
</tbody>
|
76
|
+
</c:forEach>
|
77
|
+
</c:if>
|
78
|
+
</table>
|
79
|
+
</div>
|
80
|
+
```
|
81
|
+
**DispatchIndexServlet.java**
|
82
|
+
```Java
|
83
|
+
import java.io.IOException;
|
84
|
+
import java.util.List;
|
85
|
+
|
86
|
+
import javax.persistence.EntityManager;
|
87
|
+
import javax.servlet.RequestDispatcher;
|
88
|
+
import javax.servlet.ServletException;
|
89
|
+
import javax.servlet.annotation.WebServlet;
|
90
|
+
import javax.servlet.http.HttpServlet;
|
91
|
+
import javax.servlet.http.HttpServletRequest;
|
92
|
+
import javax.servlet.http.HttpServletResponse;
|
93
|
+
|
94
|
+
import models.Trucks;
|
95
|
+
import utils.DBUtil;
|
96
|
+
|
97
|
+
|
98
|
+
@WebServlet("/dispatch/index")
|
99
|
+
public class DispatchIndexServlet extends HttpServlet {
|
100
|
+
private static final long serialVersionUID = 1L;
|
101
|
+
|
102
|
+
|
103
|
+
public DispatchIndexServlet() {
|
104
|
+
super();
|
105
|
+
}
|
106
|
+
|
107
|
+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
108
|
+
EntityManager em = DBUtil.createEntityManager();
|
109
|
+
|
110
|
+
List<Trucks> trucks = em.createNamedQuery("getAllTrucks",Trucks.class)
|
111
|
+
.getResultList();
|
112
|
+
|
113
|
+
long trucks_count = (long)em.createNamedQuery("getTrucksCount", Long.class)
|
114
|
+
.getSingleResult();
|
115
|
+
|
116
|
+
em.close();
|
117
|
+
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
request.setAttribute("trucks", trucks);
|
122
|
+
request.setAttribute("trucks_count", trucks_count);
|
123
|
+
if(request.getSession().getAttribute("flush") != null) {
|
124
|
+
request.setAttribute("flush", request.getSession().getAttribute("flush"));
|
125
|
+
request.getSession().removeAttribute("flush");
|
126
|
+
}
|
127
|
+
RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/views/dispatch/index.jsp");
|
128
|
+
rd.forward(request, response);
|
129
|
+
}
|
130
|
+
}
|
131
|
+
|
132
|
+
```
|
133
|
+
|
14
134
|
```JSP
|
135
|
+
<p>
|
136
|
+
<form method="GET" action = "DispatchCreateServlet.java">
|
137
|
+
<label for="task_date">日付</label>
|
138
|
+
<br />
|
139
|
+
<input type="date" name="task_date" value="<fmt:formatDate value='${Trucks.task_date}' pattern='M月d日' />" />
|
140
|
+
(出発地、到着地、時刻などのformのコードなので中略)
|
15
|
-
<input type="hidden" name="_token" value="${_token}" />
|
141
|
+
<input type="hidden" name="_token" value="${_token}" />
|
16
142
|
<button type="submit">登録</button>
|
17
143
|
</form>
|
18
|
-
|
144
|
+
|
19
|
-
%>
|
20
|
-
<c:if test="${task_date == date }" var="flg"/>
|
21
|
-
<c:if test="${flg}">
|
22
|
-
</c:if>
|
23
|
-
<c:if test="${!flg}">
|
24
|
-
<c:redirect url="/dispatch/index">
|
25
|
-
<div id="flush_error">
|
26
|
-
<br />
|
27
|
-
</div>
|
28
|
-
</c:redirect>
|
29
|
-
</c:if>
|
30
145
|
```
|
1
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -6,7 +6,10 @@
|
|
6
6
|
そのため、formで入力した日付と一致する日付の場所に情報を表示させようと思い、
|
7
7
|
<c:ifを使ってコードを書いてみたのですが、
|
8
8
|
期待した結果が得られなかったので、<c:if文の部分のコードを記載しますのでアドバイスを頂きたいです。
|
9
|
+
###追記
|
10
|
+
自分で試した内容について参考にさせて頂いたURL
|
11
|
+
http://struts.wasureppoi.com/jstl/02_if.html
|
9
|
-
###
|
12
|
+
### 試した内容
|
10
13
|
|
11
14
|
```JSP
|
12
15
|
<input type="hidden" name="_token" value="${_token}" /><!--ここまでのform内容をDBに登録-->
|