public class Data extends HttpServlet Это наша JSP страница String pag

  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
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
public class Data extends HttpServlet {
// Это наша JSP страница
String page = "DataPage.jsp";
String password = "root";
String login = "root";
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
// Устанавливаем соединение с БД
String url = "jdbc:postgresql://localhost:5432/root";
Connection connection = null;
ResultSet rs;
response.setContentType("text/html");
List dataList = new ArrayList();
try {
Class.forName("org.postgresql.Driver");
connection = DriverManager.getConnection(url, login, password);
String sql = "select * fiz_phone";
Statement s = connection.createStatement();
s.executeQuery(sql);
rs = s.getResultSet();
ArrayList<DBRow> rows = new ArrayList<DBRow>();
while (rs.next()) {
DBRow row = new DBRow();
row.setId(rs.getInt("id"));
row.setName(rs.getString("name"));
row.setAdress(rs.getString("adress"));
row.setPhone(rs.getString("phone"));
row.setPhone_adress(rs.getString("phone_adress"));
row.setCost(rs.getInt("cost"));
row.setExempt_type(rs.getString("exempt_type"));
row.setExempt(rs.getInt("exempt"));
row.setDate_claim(rs.getString("date_claim"));
row.setNumber_claim(rs.getInt("number_claim"));
row.setInspektor(rs.getString("inspektor"));
row.setDate_repair(rs.getString("date_repair"));
row.setPhone_cost(rs.getInt("phone_cost"));
row.setCall(rs.getString("call"));
rows.add(row)
}
rs.close();
s.close();
} catch (Exception e) {
System.out.println("Exception is ;" + e);
}
request.setAttribute("data", rows);
// Переходим на JSP страницу
RequestDispatcher dispatcher = request.getRequestDispatcher(page);
if (dispatcher != null) {
dispatcher.forward(request, response);
}
}
}
public class DBRow{
private int id;
private String name;
private String adress;
private String phone;
private String phone_adress;
private int cost;
private String exempt_type;
private int exempt;
private String date_claim;
private int number_claim;
private String inspektor;
private String date_repair;
private int phone_cost;
private String call;
public void setId(int id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setAdress(String adress) {
this.adress = adress;
}
public void setPhone(String phone) {
this.phone = phone;
}
public void setPhone_adress(String phone_adress) {
this.phone_adress = phone_adress;
}
public void setCost(int cost) {
this.cost = cost;
}
public void setExempt_type(String exempt_type) {
this.exempt_type = exempt_type;
}
public void setExempt(int exempt) {
this.exempt = exempt;
}
public void setDate_claim(String date_claim) {
this.date_claim = date_claim;
}
public void setNumber_claim(int number_claim) {
this.number_claim = number_claim;
}
public void setInspektor(String inspektor) {
this.inspektor = inspektor;
}
public void setDate_repair(String date_repair) {
this.date_repair = date_repair;
}
public void setPhone_cost(int phone_cost) {
this.phone_cost = phone_cost;
}
public void setCall(String call) {
this.call = call;
}
public String getName() {
return name;
}
public String getAdress() {
return adress;
}
public String getPhone() {
return phone;
}
public String getPhone_adress() {
return phone_adress;
}
public int getCost() {
return cost;
}
public String getExempt_type() {
return exempt_type;
}
public String getDate_claim() {
return date_claim;
}
public int getId() {
return id;
}
public int getExempt() {
return exempt;
}
public int getNumber_claim() {
return number_claim;
}
public String getInspektor() {
return inspektor;
}
public String getDate_repair() {
return date_repair;
}
public int getPhone_cost() {
return phone_cost;
}
public String getCall() {
return call;
}
}
<body>
<table border="1">
<tr>
<td ><b>ID</b></td>
<td ><b>Name</b></td>
<td ><b>Adress</b></td>
<td ><b>Phone</b></td>
<td ><b>Phone adress</b></td>
<td ><b>Cost</b></td>
<td ><b>Exempt type</b></td>
<td ><b>Exempt</b></td>
<td ><b>Date claim</b></td>
<td ><b>Number of claim</b></td>
<td ><b>Inspektor</b></td>
<td ><b>Date repair</b></td>
<td ><b>Phone cost</b></td>
<td ><b>Call</b></td>
</tr>
<c:forEach items="${data}" var="row">
<tr >
<td ><%=row.getId()%></td>
<td ><%=row.getName()%></td>
<td ><%=row.getAddress()%></td>
<td ><%=row.getPhone()%></td>
<td ><%=row.getPhone_adress%></td>
<td ><%=row.getCost()%></td>
<td ><%=row.getExempt_type()%></td>
<td ><%=row.getExempt()%></td>
<td ><%=row.getDate_claim()%></td>
<td ><%=row.getNumber_claim()%></td>
<td ><%=row.getInspektor()%></td>
<td ><%=row.getDate_repair()%></td>
<td ><%=row.getPhone_cost()%></td>
<td ><%=row.getCall()%></td>
</tr>
</c:forEach>
</table>
</body>