質問編集履歴

1

ソースをすべて記入しました。

2015/09/09 07:20

投稿

nissanngtr34
nissanngtr34

スコア24

test CHANGED
File without changes
test CHANGED
@@ -1,60 +1,296 @@
1
- ☆サブレット側
2
-
3
-
4
-
5
- GetUser gu1 = new GetUser();
6
-
7
- GetUser gu2 = new GetUser();
8
-
9
- GetUser gu3 = new GetUser();
10
-
11
-
12
-
13
- gu1.setId("yamada");
14
-
15
- gu1.setPass("pas1");
16
-
17
- gu1.setName("山田");
18
-
19
- gu1.setSex("men");
20
-
21
-
22
-
23
- gu2.setId("suzuki");
24
-
25
- gu2.setPass("pas2");
26
-
27
- gu2.setName("鈴木");
28
-
29
- gu2.setSex("men");
30
-
31
-
32
-
33
- gu3.setId("tanaka");
34
-
35
- gu3.setPass("pas3");
36
-
37
- gu3.setName("田中");
38
-
39
- gu3.setSex("men");
40
-
41
-
42
-
43
- list.add(gu1);//ユーザー1
44
-
45
- list.add(gu2);//ユーザー2
46
-
47
- list.add(gu3);//ユーザー3
48
-
49
-
50
-
51
- request.setAttribute("list",list);
52
-
53
-
54
-
55
- RequestDispatcher dispatcher = request.getRequestDispatcher("/sample_get1.jsp");
56
-
57
- dispatcher.forward(request, response);//sample_get1.jspに飛ばします。
1
+ スすべてです。
2
+
3
+ ☆Sample01.java------------------------------------------------
4
+
5
+
6
+
7
+ package sample.pg;
8
+
9
+
10
+
11
+ import java.io.IOException;
12
+
13
+ import java.util.ArrayList;
14
+
15
+ import java.util.List;
16
+
17
+
18
+
19
+ import javax.servlet.RequestDispatcher;
20
+
21
+ import javax.servlet.ServletException;
22
+
23
+ import javax.servlet.annotation.WebServlet;
24
+
25
+ import javax.servlet.http.HttpServlet;
26
+
27
+ import javax.servlet.http.HttpServletRequest;
28
+
29
+ import javax.servlet.http.HttpServletResponse;
30
+
31
+
32
+
33
+ /**
34
+
35
+ * Servlet implementation class Sample01
36
+
37
+ */
38
+
39
+ @WebServlet("/Sample01")
40
+
41
+
42
+
43
+
44
+
45
+ public class Sample01 extends HttpServlet {
46
+
47
+ private static final long serialVersionUID = 1L;
48
+
49
+
50
+
51
+ /**
52
+
53
+ * @see HttpServlet#HttpServlet()
54
+
55
+ */
56
+
57
+ public Sample01() {
58
+
59
+ super();
60
+
61
+ // TODO Auto-generated constructor stub
62
+
63
+ }
64
+
65
+
66
+
67
+ /**
68
+
69
+ * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
70
+
71
+ */
72
+
73
+ protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
74
+
75
+ // TODO Auto-generated method stub
76
+
77
+ //response.getWriter().append("Served at: ").append(request.getContextPath());
78
+
79
+
80
+
81
+ GetUser gu1 = new GetUser();
82
+
83
+ GetUser gu2 = new GetUser();
84
+
85
+ GetUser gu3 = new GetUser();
86
+
87
+
88
+
89
+ gu1.setId("yamada");
90
+
91
+ gu1.setPass("pas1");
92
+
93
+ gu1.setName("山田");
94
+
95
+ gu1.setSex("men");
96
+
97
+
98
+
99
+ gu2.setId("suzuki");
100
+
101
+ gu2.setPass("pas2");
102
+
103
+ gu2.setName("鈴木");
104
+
105
+ gu2.setSex("men");
106
+
107
+
108
+
109
+ gu3.setId("tanaka");
110
+
111
+ gu3.setPass("pas3");
112
+
113
+ gu3.setName("田中");
114
+
115
+ gu3.setSex("men");
116
+
117
+
118
+
119
+
120
+
121
+ List list = new ArrayList();
122
+
123
+ list.add(gu1);
124
+
125
+ list.add(gu2);
126
+
127
+ list.add(gu3);
128
+
129
+
130
+
131
+
132
+
133
+ request.setAttribute("list",list);
134
+
135
+
136
+
137
+
138
+
139
+
140
+
141
+ RequestDispatcher dispatcher = request.getRequestDispatcher("/sample_get1.jsp");
142
+
143
+ dispatcher.forward(request, response);
144
+
145
+
146
+
147
+
148
+
149
+ }
150
+
151
+
152
+
153
+ /**
154
+
155
+ * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
156
+
157
+ */
158
+
159
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
160
+
161
+ // TODO Auto-generated method stub
162
+
163
+ //doGet(request, response);
164
+
165
+
166
+
167
+
168
+
169
+ }
170
+
171
+ }
172
+
173
+
174
+
175
+
176
+
177
+ ☆GetUser.java------------------------------------------------
178
+
179
+ package sample.pg;
180
+
181
+
182
+
183
+ class GetUser{
184
+
185
+ private String id;
186
+
187
+ private String pass;
188
+
189
+ private String name;
190
+
191
+ private String sex;
192
+
193
+
194
+
195
+ public String getId(){
196
+
197
+ return this.id;
198
+
199
+ }
200
+
201
+ public String getPass(){
202
+
203
+ return this.pass;
204
+
205
+ }
206
+
207
+ public String getName(){
208
+
209
+ return this.name;
210
+
211
+ }
212
+
213
+ public String getSex(){
214
+
215
+ return this.sex;
216
+
217
+ }
218
+
219
+
220
+
221
+ public void setId(String id){
222
+
223
+ this.id=id;
224
+
225
+ }
226
+
227
+ public void setPass(String pass){
228
+
229
+ this.pass=pass;
230
+
231
+ }
232
+
233
+ public void setName(String name){
234
+
235
+ this.name=name;
236
+
237
+ }
238
+
239
+ public void setSex(String sex){
240
+
241
+ this.sex=sex;
242
+
243
+ }
244
+
245
+ }
246
+
247
+
248
+
249
+ ☆sample_get1.jsp------------------------------------------
250
+
251
+
252
+
253
+ <%@ page contentType="text/html;charset=UTF-8" %>
254
+
255
+ <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
256
+
257
+ <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
258
+
259
+
260
+
261
+
262
+
263
+ <!DOCTYPE html">
264
+
265
+ <html>
266
+
267
+ <head>
268
+
269
+ <meta charset="UTF-8">
270
+
271
+ <title>Insert title here</title>
272
+
273
+ </head>
274
+
275
+ <body>
276
+
277
+ <table border="1">
278
+
279
+ <tr>
280
+
281
+ <c:forEach var="item" items="${requestScope['list']}">
282
+
283
+ <td>${item.getId()} </td>
284
+
285
+ </c:forEach>
286
+
287
+ </tr>
288
+
289
+ </table>
290
+
291
+ </body>
292
+
293
+ </html>
58
294
 
59
295
 
60
296
 
@@ -75,53 +311,3 @@
75
311
  JSP側でインスタンスをする処理が必要になってくるのでしょうか?
76
312
 
77
313
  よろしくお願い致します。
78
-
79
-
80
-
81
- ☆JSP側
82
-
83
- <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
84
-
85
- pageEncoding="UTF-8"%>
86
-
87
- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
88
-
89
- <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
90
-
91
- <%@ page import="sample.pg.Sample01" %>
92
-
93
-
94
-
95
-
96
-
97
- <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
98
-
99
- <html>
100
-
101
- <head>
102
-
103
- <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
104
-
105
- <title>Insert title here</title>
106
-
107
- </head>
108
-
109
- <body>
110
-
111
- <table border="1">
112
-
113
- <c:forEach var="item" items="list">
114
-
115
- <tr>
116
-
117
- <td>${list.getId()} </td>
118
-
119
- </tr>
120
-
121
- </c:forEach>
122
-
123
- </table>
124
-
125
- </body>
126
-
127
- </html>