質問編集履歴
6
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -12,28 +12,18 @@
|
|
12
12
|
|
13
13
|
検索条件は以下に記します。
|
14
14
|
|
15
|
+
|
16
|
+
|
17
|
+
(追記)
|
18
|
+
|
15
|
-
|
19
|
+
ソースコードを書き換えたところ、ファイルの読み込みに失敗してしまいます。
|
20
|
+
|
21
|
+
なぜでしょうか?
|
16
22
|
|
17
23
|
ご教授いただけますと幸いです。
|
18
24
|
|
19
25
|
|
20
26
|
|
21
|
-
(追記)
|
22
|
-
|
23
|
-
該当のソースコード2で記載したプログラムで実行しようとしましたが、
|
24
|
-
|
25
|
-
画面遷移後にコード表示される状態になってしまいました。
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
(追記)
|
30
|
-
|
31
|
-
ソースコードを書き換えたところ、ファイルの読み込みに失敗してしまいます。
|
32
|
-
|
33
|
-
なぜでしょうか?
|
34
|
-
|
35
|
-
|
36
|
-
|
37
27
|
###想定していたことと結果
|
38
28
|
|
39
29
|
想定:検索結果に一致したレコードが出てくる
|
5
追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,6 +26,14 @@
|
|
26
26
|
|
27
27
|
|
28
28
|
|
29
|
+
(追記)
|
30
|
+
|
31
|
+
ソースコードを書き換えたところ、ファイルの読み込みに失敗してしまいます。
|
32
|
+
|
33
|
+
なぜでしょうか?
|
34
|
+
|
35
|
+
|
36
|
+
|
29
37
|
###想定していたことと結果
|
30
38
|
|
31
39
|
想定:検索結果に一致したレコードが出てくる
|
@@ -132,9 +140,9 @@
|
|
132
140
|
|
133
141
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
134
142
|
|
135
|
-
<%@ page language="java" contentType="text/html; charset=
|
143
|
+
<%@ page language="java" contentType="text/html; charset=SJIS"
|
136
|
-
|
144
|
+
|
137
|
-
pageEncoding="
|
145
|
+
pageEncoding="SJIS"%>
|
138
146
|
|
139
147
|
<%@page import="java.io.*, java.util.*, java.util.regex.*" %>
|
140
148
|
|
@@ -194,7 +202,7 @@
|
|
194
202
|
|
195
203
|
<head>
|
196
204
|
|
197
|
-
<meta http-equiv="Content-Type" content="text/html; charset=
|
205
|
+
<meta http-equiv="Content-Type" content="text/html; charset=SJIS">
|
198
206
|
|
199
207
|
<title>resultcsv</title>
|
200
208
|
|
@@ -204,7 +212,7 @@
|
|
204
212
|
|
205
213
|
<%
|
206
214
|
|
207
|
-
request.setCharacterEncoding("S
|
215
|
+
request.setCharacterEncoding("SJIS");
|
208
216
|
|
209
217
|
String searchBuilding1 = escapeChar(request.getParameter("number1"));
|
210
218
|
|
@@ -226,6 +234,8 @@
|
|
226
234
|
|
227
235
|
|
228
236
|
|
237
|
+
|
238
|
+
|
229
239
|
<h2>検索条件:「<%=searchBuilding1%>」、「<%=searchBuilding2%>」、「<%=searchBuilding3%>」を含む</h2>
|
230
240
|
|
231
241
|
|
@@ -254,7 +264,11 @@
|
|
254
264
|
|
255
265
|
StringTokenizer stk;
|
256
266
|
|
257
|
-
File
|
267
|
+
File f = new File("results.csv");
|
268
|
+
|
269
|
+
FileInputStream input = new FileInputStream(f);
|
270
|
+
|
271
|
+
InputStreamReader fr = new InputStreamReader(input,"SJIS");
|
258
272
|
|
259
273
|
BufferedReader br = new BufferedReader(fr);
|
260
274
|
|
@@ -298,25 +312,35 @@
|
|
298
312
|
|
299
313
|
}
|
300
314
|
|
315
|
+
/*
|
316
|
+
|
301
|
-
Matcher searchMatcher1 = searchPattern1.matcher(strData[
|
317
|
+
Matcher searchMatcher1 = searchPattern1.matcher(strData[0]);
|
302
318
|
|
303
319
|
Matcher searchMatcher2 = searchPattern2.matcher(strData[1]);
|
304
320
|
|
305
|
-
Matcher searchMatcher3 = searchPattern3.matcher(strData[
|
321
|
+
Matcher searchMatcher3 = searchPattern3.matcher(strData[2]);
|
306
|
-
|
322
|
+
|
307
|
-
Matcher searchMatcher4 = searchPattern4.matcher(strData[
|
323
|
+
Matcher searchMatcher4 = searchPattern4.matcher(strData[3]);
|
308
|
-
|
324
|
+
|
309
|
-
Matcher searchMatcher5 = searchPattern5.matcher(strData[
|
325
|
+
Matcher searchMatcher5 = searchPattern5.matcher(strData[3]);
|
310
|
-
|
326
|
+
|
311
|
-
Matcher searchMatcher6 = searchPattern6.matcher(strData[
|
327
|
+
Matcher searchMatcher6 = searchPattern6.matcher(strData[4]);
|
312
|
-
|
328
|
+
|
313
|
-
Matcher searchMatcher7 = searchPattern7.matcher(strData[
|
329
|
+
Matcher searchMatcher7 = searchPattern7.matcher(strData[4]);
|
330
|
+
|
314
|
-
|
331
|
+
*/
|
332
|
+
|
315
|
-
i
|
333
|
+
int cost = Integer.parseInt(strData[3]);
|
316
|
-
|
334
|
+
|
317
|
-
|
335
|
+
int cost1 = Integer.parseInt("cost1");
|
318
|
-
|
336
|
+
|
319
|
-
|
337
|
+
int cost2 = Integer.parseInt("cost2");
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
if (strData[0]=="number1"&&strData[1]=="number2"&&strData[2]=="name"&&(cost>=cost1||cost<=cost2)&&
|
342
|
+
|
343
|
+
(strData[4].compareTo("date1")<0&&strData[4].compareTo("date2")>0)) {
|
320
344
|
|
321
345
|
out.println("<tr>");
|
322
346
|
|
4
k
test
CHANGED
File without changes
|
test
CHANGED
@@ -26,6 +26,12 @@
|
|
26
26
|
|
27
27
|
|
28
28
|
|
29
|
+
###想定していたことと結果
|
30
|
+
|
31
|
+
想定:検索結果に一致したレコードが出てくる
|
32
|
+
|
33
|
+
現状:ソースコードが表示されるだけになっている
|
34
|
+
|
29
35
|
|
30
36
|
|
31
37
|
###該当のソースコード
|
3
コード追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -18,6 +18,14 @@
|
|
18
18
|
|
19
19
|
|
20
20
|
|
21
|
+
(追記)
|
22
|
+
|
23
|
+
該当のソースコード2で記載したプログラムで実行しようとしましたが、
|
24
|
+
|
25
|
+
画面遷移後にコード表示される状態になってしまいました。
|
26
|
+
|
27
|
+
|
28
|
+
|
21
29
|
|
22
30
|
|
23
31
|
###該当のソースコード
|
@@ -48,7 +56,7 @@
|
|
48
56
|
|
49
57
|
<br>
|
50
58
|
|
51
|
-
<form action="result.
|
59
|
+
<form action="result.jsp" method="post">
|
52
60
|
|
53
61
|
請求書番号<input type="text" name="number1">
|
54
62
|
|
@@ -111,3 +119,237 @@
|
|
111
119
|
</body>
|
112
120
|
|
113
121
|
</html>
|
122
|
+
|
123
|
+
|
124
|
+
|
125
|
+
###該当のソースコード2
|
126
|
+
|
127
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
128
|
+
|
129
|
+
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
130
|
+
|
131
|
+
pageEncoding="UTF-8"%>
|
132
|
+
|
133
|
+
<%@page import="java.io.*, java.util.*, java.util.regex.*" %>
|
134
|
+
|
135
|
+
<%!
|
136
|
+
|
137
|
+
private String escapeChar(String strInput){
|
138
|
+
|
139
|
+
StringBuffer strOutput=new StringBuffer();
|
140
|
+
|
141
|
+
for(int i=0;i<strInput.length();i++){
|
142
|
+
|
143
|
+
switch(strInput.charAt(i)){
|
144
|
+
|
145
|
+
case '<' :
|
146
|
+
|
147
|
+
strOutput.append("<");
|
148
|
+
|
149
|
+
break;
|
150
|
+
|
151
|
+
case '>' :
|
152
|
+
|
153
|
+
strOutput.append(">");
|
154
|
+
|
155
|
+
break;
|
156
|
+
|
157
|
+
case '&' :
|
158
|
+
|
159
|
+
strOutput.append("&");
|
160
|
+
|
161
|
+
break;
|
162
|
+
|
163
|
+
case '"' :
|
164
|
+
|
165
|
+
strOutput.append(""");
|
166
|
+
|
167
|
+
break;
|
168
|
+
|
169
|
+
default :
|
170
|
+
|
171
|
+
strOutput.append(strInput.charAt(i));
|
172
|
+
|
173
|
+
break;
|
174
|
+
|
175
|
+
}
|
176
|
+
|
177
|
+
}
|
178
|
+
|
179
|
+
return strOutput.toString();
|
180
|
+
|
181
|
+
}
|
182
|
+
|
183
|
+
%>
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
<html>
|
188
|
+
|
189
|
+
<head>
|
190
|
+
|
191
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
192
|
+
|
193
|
+
<title>resultcsv</title>
|
194
|
+
|
195
|
+
</head>
|
196
|
+
|
197
|
+
<body>
|
198
|
+
|
199
|
+
<%
|
200
|
+
|
201
|
+
request.setCharacterEncoding("Shift_JIS");
|
202
|
+
|
203
|
+
String searchBuilding1 = escapeChar(request.getParameter("number1"));
|
204
|
+
|
205
|
+
String searchBuilding2 = escapeChar(request.getParameter("number2"));
|
206
|
+
|
207
|
+
String searchBuilding3 = escapeChar(request.getParameter("name"));
|
208
|
+
|
209
|
+
String searchBuilding4 = escapeChar(request.getParameter("cost1"));
|
210
|
+
|
211
|
+
String searchBuilding5 = escapeChar(request.getParameter("cost2"));
|
212
|
+
|
213
|
+
String searchBuilding6 = escapeChar(request.getParameter("date1"));
|
214
|
+
|
215
|
+
String searchBuilding7 = escapeChar(request.getParameter("date2"));
|
216
|
+
|
217
|
+
%>
|
218
|
+
|
219
|
+
<h1>検索結果</h1>
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
<h2>検索条件:「<%=searchBuilding1%>」、「<%=searchBuilding2%>」、「<%=searchBuilding3%>」を含む</h2>
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
<table border="1">
|
228
|
+
|
229
|
+
<tr>
|
230
|
+
|
231
|
+
<th>注文書番号</th>
|
232
|
+
|
233
|
+
<th>請求書番号</th>
|
234
|
+
|
235
|
+
<th>業者名</th>
|
236
|
+
|
237
|
+
<th>日付</th>
|
238
|
+
|
239
|
+
<th>金額</th>
|
240
|
+
|
241
|
+
</tr>
|
242
|
+
|
243
|
+
|
244
|
+
|
245
|
+
<%
|
246
|
+
|
247
|
+
String tmp;
|
248
|
+
|
249
|
+
StringTokenizer stk;
|
250
|
+
|
251
|
+
FileReader fr = new FileReader(application.getRealPath("result.csv"));
|
252
|
+
|
253
|
+
BufferedReader br = new BufferedReader(fr);
|
254
|
+
|
255
|
+
int i, num, flag=0;
|
256
|
+
|
257
|
+
String[] strData = new String[10];
|
258
|
+
|
259
|
+
|
260
|
+
|
261
|
+
Pattern searchPattern1 = Pattern.compile(searchBuilding1);
|
262
|
+
|
263
|
+
Pattern searchPattern2 = Pattern.compile(searchBuilding2);
|
264
|
+
|
265
|
+
Pattern searchPattern3 = Pattern.compile(searchBuilding3);
|
266
|
+
|
267
|
+
Pattern searchPattern4 = Pattern.compile(searchBuilding4);
|
268
|
+
|
269
|
+
Pattern searchPattern5 = Pattern.compile(searchBuilding5);
|
270
|
+
|
271
|
+
Pattern searchPattern6 = Pattern.compile(searchBuilding6);
|
272
|
+
|
273
|
+
Pattern searchPattern7 = Pattern.compile(searchBuilding7);
|
274
|
+
|
275
|
+
|
276
|
+
|
277
|
+
while (br.ready()) {
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
tmp = br.readLine();
|
282
|
+
|
283
|
+
stk = new StringTokenizer(tmp, ",");
|
284
|
+
|
285
|
+
num = stk.countTokens();
|
286
|
+
|
287
|
+
|
288
|
+
|
289
|
+
for (i=0; i<num; i++) {
|
290
|
+
|
291
|
+
strData[i] = (String) stk.nextToken();
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
Matcher searchMatcher1 = searchPattern1.matcher(strData[1]);
|
296
|
+
|
297
|
+
Matcher searchMatcher2 = searchPattern2.matcher(strData[1]);
|
298
|
+
|
299
|
+
Matcher searchMatcher3 = searchPattern3.matcher(strData[1]);
|
300
|
+
|
301
|
+
Matcher searchMatcher4 = searchPattern4.matcher(strData[1]);
|
302
|
+
|
303
|
+
Matcher searchMatcher5 = searchPattern5.matcher(strData[1]);
|
304
|
+
|
305
|
+
Matcher searchMatcher6 = searchPattern6.matcher(strData[1]);
|
306
|
+
|
307
|
+
Matcher searchMatcher7 = searchPattern7.matcher(strData[1]);
|
308
|
+
|
309
|
+
if (searchMatcher1.find()||searchMatcher2.find()||searchMatcher3.find()||
|
310
|
+
|
311
|
+
searchMatcher4.find()||searchMatcher5.find()||searchMatcher6.find()
|
312
|
+
|
313
|
+
||searchMatcher7.find()) {
|
314
|
+
|
315
|
+
out.println("<tr>");
|
316
|
+
|
317
|
+
for (i=0; i<num; i++) {
|
318
|
+
|
319
|
+
out.println("<td>" + strData[i] + "</td>");
|
320
|
+
|
321
|
+
}
|
322
|
+
|
323
|
+
out.println("</tr>");
|
324
|
+
|
325
|
+
flag = 1;
|
326
|
+
|
327
|
+
}
|
328
|
+
|
329
|
+
}
|
330
|
+
|
331
|
+
br.close();
|
332
|
+
|
333
|
+
%>
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
</table>
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
<%
|
342
|
+
|
343
|
+
if (flag == 0) {
|
344
|
+
|
345
|
+
out.println("<p>該当する建物は見つかりませんでした。</p>");
|
346
|
+
|
347
|
+
}
|
348
|
+
|
349
|
+
%>
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
</body>
|
354
|
+
|
355
|
+
</html>
|
2
k
test
CHANGED
File without changes
|
test
CHANGED
@@ -11,6 +11,10 @@
|
|
11
11
|
HTMLで作成したページにて、入力した条件に合うCSVのデータを抽出するプログラムを書きたいと考えています。
|
12
12
|
|
13
13
|
検索条件は以下に記します。
|
14
|
+
|
15
|
+
どのようにプログラムを設計すればいいのかわかりません。
|
16
|
+
|
17
|
+
ご教授いただけますと幸いです。
|
14
18
|
|
15
19
|
|
16
20
|
|
1
初心者です
test
CHANGED
File without changes
|
test
CHANGED
File without changes
|