質問編集履歴
6
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,16 +5,11 @@
|
|
5
5
|
###前提・実現したいこと
|
6
6
|
HTMLで作成したページにて、入力した条件に合うCSVのデータを抽出するプログラムを書きたいと考えています。
|
7
7
|
検索条件は以下に記します。
|
8
|
-
どのようにプログラムを設計すればいいのかわかりません。
|
9
|
-
ご教授いただけますと幸いです。
|
10
8
|
|
11
9
|
(追記)
|
12
|
-
該当のソースコード2で記載したプログラムで実行しようとしましたが、
|
13
|
-
画面遷移後にコード表示される状態になってしまいました。
|
14
|
-
|
15
|
-
(追記)
|
16
10
|
ソースコードを書き換えたところ、ファイルの読み込みに失敗してしまいます。
|
17
11
|
なぜでしょうか?
|
12
|
+
ご教授いただけますと幸いです。
|
18
13
|
|
19
14
|
###想定していたことと結果
|
20
15
|
想定:検索結果に一致したレコードが出てくる
|
5
追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,6 +12,10 @@
|
|
12
12
|
該当のソースコード2で記載したプログラムで実行しようとしましたが、
|
13
13
|
画面遷移後にコード表示される状態になってしまいました。
|
14
14
|
|
15
|
+
(追記)
|
16
|
+
ソースコードを書き換えたところ、ファイルの読み込みに失敗してしまいます。
|
17
|
+
なぜでしょうか?
|
18
|
+
|
15
19
|
###想定していたことと結果
|
16
20
|
想定:検索結果に一致したレコードが出てくる
|
17
21
|
現状:ソースコードが表示されるだけになっている
|
@@ -65,8 +69,8 @@
|
|
65
69
|
|
66
70
|
###該当のソースコード2
|
67
71
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
68
|
-
<%@ page language="java" contentType="text/html; charset=
|
72
|
+
<%@ page language="java" contentType="text/html; charset=SJIS"
|
69
|
-
pageEncoding="
|
73
|
+
pageEncoding="SJIS"%>
|
70
74
|
<%@page import="java.io.*, java.util.*, java.util.regex.*" %>
|
71
75
|
<%!
|
72
76
|
private String escapeChar(String strInput){
|
@@ -96,12 +100,12 @@
|
|
96
100
|
|
97
101
|
<html>
|
98
102
|
<head>
|
99
|
-
<meta http-equiv="Content-Type" content="text/html; charset=
|
103
|
+
<meta http-equiv="Content-Type" content="text/html; charset=SJIS">
|
100
104
|
<title>resultcsv</title>
|
101
105
|
</head>
|
102
106
|
<body>
|
103
107
|
<%
|
104
|
-
request.setCharacterEncoding("
|
108
|
+
request.setCharacterEncoding("SJIS");
|
105
109
|
String searchBuilding1 = escapeChar(request.getParameter("number1"));
|
106
110
|
String searchBuilding2 = escapeChar(request.getParameter("number2"));
|
107
111
|
String searchBuilding3 = escapeChar(request.getParameter("name"));
|
@@ -112,6 +116,7 @@
|
|
112
116
|
%>
|
113
117
|
<h1>検索結果</h1>
|
114
118
|
|
119
|
+
|
115
120
|
<h2>検索条件:「<%=searchBuilding1%>」、「<%=searchBuilding2%>」、「<%=searchBuilding3%>」を含む</h2>
|
116
121
|
|
117
122
|
<table border="1">
|
@@ -126,7 +131,9 @@
|
|
126
131
|
<%
|
127
132
|
String tmp;
|
128
133
|
StringTokenizer stk;
|
129
|
-
|
134
|
+
File f = new File("results.csv");
|
135
|
+
FileInputStream input = new FileInputStream(f);
|
136
|
+
InputStreamReader fr = new InputStreamReader(input,"SJIS");
|
130
137
|
BufferedReader br = new BufferedReader(fr);
|
131
138
|
int i, num, flag=0;
|
132
139
|
String[] strData = new String[10];
|
@@ -148,16 +155,21 @@
|
|
148
155
|
for (i=0; i<num; i++) {
|
149
156
|
strData[i] = (String) stk.nextToken();
|
150
157
|
}
|
158
|
+
/*
|
151
|
-
Matcher searchMatcher1 = searchPattern1.matcher(strData[
|
159
|
+
Matcher searchMatcher1 = searchPattern1.matcher(strData[0]);
|
152
160
|
Matcher searchMatcher2 = searchPattern2.matcher(strData[1]);
|
153
|
-
Matcher searchMatcher3 = searchPattern3.matcher(strData[
|
161
|
+
Matcher searchMatcher3 = searchPattern3.matcher(strData[2]);
|
154
|
-
Matcher searchMatcher4 = searchPattern4.matcher(strData[
|
162
|
+
Matcher searchMatcher4 = searchPattern4.matcher(strData[3]);
|
155
|
-
Matcher searchMatcher5 = searchPattern5.matcher(strData[
|
163
|
+
Matcher searchMatcher5 = searchPattern5.matcher(strData[3]);
|
156
|
-
Matcher searchMatcher6 = searchPattern6.matcher(strData[
|
164
|
+
Matcher searchMatcher6 = searchPattern6.matcher(strData[4]);
|
157
|
-
Matcher searchMatcher7 = searchPattern7.matcher(strData[
|
165
|
+
Matcher searchMatcher7 = searchPattern7.matcher(strData[4]);
|
166
|
+
*/
|
158
|
-
|
167
|
+
int cost = Integer.parseInt(strData[3]);
|
159
|
-
|
168
|
+
int cost1 = Integer.parseInt("cost1");
|
160
|
-
|
169
|
+
int cost2 = Integer.parseInt("cost2");
|
170
|
+
|
171
|
+
if (strData[0]=="number1"&&strData[1]=="number2"&&strData[2]=="name"&&(cost>=cost1||cost<=cost2)&&
|
172
|
+
(strData[4].compareTo("date1")<0&&strData[4].compareTo("date2")>0)) {
|
161
173
|
out.println("<tr>");
|
162
174
|
for (i=0; i<num; i++) {
|
163
175
|
out.println("<td>" + strData[i] + "</td>");
|
4
k
title
CHANGED
File without changes
|
body
CHANGED
@@ -12,6 +12,9 @@
|
|
12
12
|
該当のソースコード2で記載したプログラムで実行しようとしましたが、
|
13
13
|
画面遷移後にコード表示される状態になってしまいました。
|
14
14
|
|
15
|
+
###想定していたことと結果
|
16
|
+
想定:検索結果に一致したレコードが出てくる
|
17
|
+
現状:ソースコードが表示されるだけになっている
|
15
18
|
|
16
19
|
###該当のソースコード
|
17
20
|
<!DOCTYPE html>
|
3
コード追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -8,7 +8,11 @@
|
|
8
8
|
どのようにプログラムを設計すればいいのかわかりません。
|
9
9
|
ご教授いただけますと幸いです。
|
10
10
|
|
11
|
+
(追記)
|
12
|
+
該当のソースコード2で記載したプログラムで実行しようとしましたが、
|
13
|
+
画面遷移後にコード表示される状態になってしまいました。
|
11
14
|
|
15
|
+
|
12
16
|
###該当のソースコード
|
13
17
|
<!DOCTYPE html>
|
14
18
|
<html>
|
@@ -23,7 +27,7 @@
|
|
23
27
|
<p>注文書番号、請求書番号、業者名、日付範囲を入力し、検索ボタンをクリックして下さい。
|
24
28
|
</p>
|
25
29
|
<br>
|
26
|
-
<form action="result.
|
30
|
+
<form action="result.jsp" method="post">
|
27
31
|
請求書番号<input type="text" name="number1">
|
28
32
|
<br>
|
29
33
|
<br>
|
@@ -54,4 +58,121 @@
|
|
54
58
|
<br>
|
55
59
|
</form>
|
56
60
|
</body>
|
61
|
+
</html>
|
62
|
+
|
63
|
+
###該当のソースコード2
|
64
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
65
|
+
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
66
|
+
pageEncoding="UTF-8"%>
|
67
|
+
<%@page import="java.io.*, java.util.*, java.util.regex.*" %>
|
68
|
+
<%!
|
69
|
+
private String escapeChar(String strInput){
|
70
|
+
StringBuffer strOutput=new StringBuffer();
|
71
|
+
for(int i=0;i<strInput.length();i++){
|
72
|
+
switch(strInput.charAt(i)){
|
73
|
+
case '<' :
|
74
|
+
strOutput.append("<");
|
75
|
+
break;
|
76
|
+
case '>' :
|
77
|
+
strOutput.append(">");
|
78
|
+
break;
|
79
|
+
case '&' :
|
80
|
+
strOutput.append("&");
|
81
|
+
break;
|
82
|
+
case '"' :
|
83
|
+
strOutput.append(""");
|
84
|
+
break;
|
85
|
+
default :
|
86
|
+
strOutput.append(strInput.charAt(i));
|
87
|
+
break;
|
88
|
+
}
|
89
|
+
}
|
90
|
+
return strOutput.toString();
|
91
|
+
}
|
92
|
+
%>
|
93
|
+
|
94
|
+
<html>
|
95
|
+
<head>
|
96
|
+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
97
|
+
<title>resultcsv</title>
|
98
|
+
</head>
|
99
|
+
<body>
|
100
|
+
<%
|
101
|
+
request.setCharacterEncoding("Shift_JIS");
|
102
|
+
String searchBuilding1 = escapeChar(request.getParameter("number1"));
|
103
|
+
String searchBuilding2 = escapeChar(request.getParameter("number2"));
|
104
|
+
String searchBuilding3 = escapeChar(request.getParameter("name"));
|
105
|
+
String searchBuilding4 = escapeChar(request.getParameter("cost1"));
|
106
|
+
String searchBuilding5 = escapeChar(request.getParameter("cost2"));
|
107
|
+
String searchBuilding6 = escapeChar(request.getParameter("date1"));
|
108
|
+
String searchBuilding7 = escapeChar(request.getParameter("date2"));
|
109
|
+
%>
|
110
|
+
<h1>検索結果</h1>
|
111
|
+
|
112
|
+
<h2>検索条件:「<%=searchBuilding1%>」、「<%=searchBuilding2%>」、「<%=searchBuilding3%>」を含む</h2>
|
113
|
+
|
114
|
+
<table border="1">
|
115
|
+
<tr>
|
116
|
+
<th>注文書番号</th>
|
117
|
+
<th>請求書番号</th>
|
118
|
+
<th>業者名</th>
|
119
|
+
<th>日付</th>
|
120
|
+
<th>金額</th>
|
121
|
+
</tr>
|
122
|
+
|
123
|
+
<%
|
124
|
+
String tmp;
|
125
|
+
StringTokenizer stk;
|
126
|
+
FileReader fr = new FileReader(application.getRealPath("result.csv"));
|
127
|
+
BufferedReader br = new BufferedReader(fr);
|
128
|
+
int i, num, flag=0;
|
129
|
+
String[] strData = new String[10];
|
130
|
+
|
131
|
+
Pattern searchPattern1 = Pattern.compile(searchBuilding1);
|
132
|
+
Pattern searchPattern2 = Pattern.compile(searchBuilding2);
|
133
|
+
Pattern searchPattern3 = Pattern.compile(searchBuilding3);
|
134
|
+
Pattern searchPattern4 = Pattern.compile(searchBuilding4);
|
135
|
+
Pattern searchPattern5 = Pattern.compile(searchBuilding5);
|
136
|
+
Pattern searchPattern6 = Pattern.compile(searchBuilding6);
|
137
|
+
Pattern searchPattern7 = Pattern.compile(searchBuilding7);
|
138
|
+
|
139
|
+
while (br.ready()) {
|
140
|
+
|
141
|
+
tmp = br.readLine();
|
142
|
+
stk = new StringTokenizer(tmp, ",");
|
143
|
+
num = stk.countTokens();
|
144
|
+
|
145
|
+
for (i=0; i<num; i++) {
|
146
|
+
strData[i] = (String) stk.nextToken();
|
147
|
+
}
|
148
|
+
Matcher searchMatcher1 = searchPattern1.matcher(strData[1]);
|
149
|
+
Matcher searchMatcher2 = searchPattern2.matcher(strData[1]);
|
150
|
+
Matcher searchMatcher3 = searchPattern3.matcher(strData[1]);
|
151
|
+
Matcher searchMatcher4 = searchPattern4.matcher(strData[1]);
|
152
|
+
Matcher searchMatcher5 = searchPattern5.matcher(strData[1]);
|
153
|
+
Matcher searchMatcher6 = searchPattern6.matcher(strData[1]);
|
154
|
+
Matcher searchMatcher7 = searchPattern7.matcher(strData[1]);
|
155
|
+
if (searchMatcher1.find()||searchMatcher2.find()||searchMatcher3.find()||
|
156
|
+
searchMatcher4.find()||searchMatcher5.find()||searchMatcher6.find()
|
157
|
+
||searchMatcher7.find()) {
|
158
|
+
out.println("<tr>");
|
159
|
+
for (i=0; i<num; i++) {
|
160
|
+
out.println("<td>" + strData[i] + "</td>");
|
161
|
+
}
|
162
|
+
out.println("</tr>");
|
163
|
+
flag = 1;
|
164
|
+
}
|
165
|
+
}
|
166
|
+
br.close();
|
167
|
+
%>
|
168
|
+
|
169
|
+
</table>
|
170
|
+
|
171
|
+
<%
|
172
|
+
if (flag == 0) {
|
173
|
+
out.println("<p>該当する建物は見つかりませんでした。</p>");
|
174
|
+
}
|
175
|
+
%>
|
176
|
+
|
177
|
+
</body>
|
57
178
|
</html>
|
2
k
title
CHANGED
File without changes
|
body
CHANGED
@@ -5,6 +5,8 @@
|
|
5
5
|
###前提・実現したいこと
|
6
6
|
HTMLで作成したページにて、入力した条件に合うCSVのデータを抽出するプログラムを書きたいと考えています。
|
7
7
|
検索条件は以下に記します。
|
8
|
+
どのようにプログラムを設計すればいいのかわかりません。
|
9
|
+
ご教授いただけますと幸いです。
|
8
10
|
|
9
11
|
|
10
12
|
###該当のソースコード
|
1
初心者です
title
CHANGED
File without changes
|
body
CHANGED
File without changes
|