質問編集履歴
1
ソースをすべて記入しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,64 +1,157 @@
|
|
1
|
-
|
1
|
+
ソースすべてです。
|
2
|
+
☆Sample01.java------------------------------------------------
|
2
3
|
|
3
|
-
|
4
|
+
package sample.pg;
|
4
|
-
GetUser gu2 = new GetUser();
|
5
|
-
GetUser gu3 = new GetUser();
|
6
5
|
|
6
|
+
import java.io.IOException;
|
7
|
-
|
7
|
+
import java.util.ArrayList;
|
8
|
-
gu1.setPass("pas1");
|
9
|
-
|
8
|
+
import java.util.List;
|
10
|
-
gu1.setSex("men");
|
11
9
|
|
12
|
-
gu2.setId("suzuki");
|
13
|
-
gu2.setPass("pas2");
|
14
|
-
|
10
|
+
import javax.servlet.RequestDispatcher;
|
11
|
+
import javax.servlet.ServletException;
|
15
|
-
|
12
|
+
import javax.servlet.annotation.WebServlet;
|
13
|
+
import javax.servlet.http.HttpServlet;
|
14
|
+
import javax.servlet.http.HttpServletRequest;
|
15
|
+
import javax.servlet.http.HttpServletResponse;
|
16
16
|
|
17
|
+
/**
|
17
|
-
|
18
|
+
* Servlet implementation class Sample01
|
18
|
-
gu3.setPass("pas3");
|
19
|
-
|
19
|
+
*/
|
20
|
-
|
20
|
+
@WebServlet("/Sample01")
|
21
21
|
|
22
|
-
list.add(gu1);//ユーザー1
|
23
|
-
list.add(gu2);//ユーザー2
|
24
|
-
list.add(gu3);//ユーザー3
|
25
22
|
|
23
|
+
public class Sample01 extends HttpServlet {
|
26
|
-
|
24
|
+
private static final long serialVersionUID = 1L;
|
27
25
|
|
26
|
+
/**
|
28
|
-
|
27
|
+
* @see HttpServlet#HttpServlet()
|
28
|
+
*/
|
29
|
+
public Sample01() {
|
30
|
+
super();
|
29
|
-
|
31
|
+
// TODO Auto-generated constructor stub
|
32
|
+
}
|
30
33
|
|
34
|
+
/**
|
35
|
+
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
|
36
|
+
*/
|
37
|
+
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
38
|
+
// TODO Auto-generated method stub
|
39
|
+
//response.getWriter().append("Served at: ").append(request.getContextPath());
|
31
40
|
|
32
|
-
各ユーザー(gu○)のインスタンスを作り、それを各リストに入れました。
|
33
|
-
|
41
|
+
GetUser gu1 = new GetUser();
|
42
|
+
GetUser gu2 = new GetUser();
|
43
|
+
GetUser gu3 = new GetUser();
|
34
44
|
|
45
|
+
gu1.setId("yamada");
|
35
|
-
|
46
|
+
gu1.setPass("pas1");
|
47
|
+
gu1.setName("山田");
|
48
|
+
gu1.setSex("men");
|
36
49
|
|
37
|
-
もしかしてJSP側でJAVAで作ったクラスを読み込ませる処理が必要だったりするのでしょうか?
|
38
|
-
|
50
|
+
gu2.setId("suzuki");
|
51
|
+
gu2.setPass("pas2");
|
39
|
-
|
52
|
+
gu2.setName("鈴木");
|
53
|
+
gu2.setSex("men");
|
40
54
|
|
41
|
-
☆JSP側
|
42
|
-
|
55
|
+
gu3.setId("tanaka");
|
56
|
+
gu3.setPass("pas3");
|
57
|
+
gu3.setName("田中");
|
43
|
-
|
58
|
+
gu3.setSex("men");
|
44
|
-
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
|
45
|
-
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
|
46
|
-
<%@ page import="sample.pg.Sample01" %>
|
47
59
|
|
48
60
|
|
61
|
+
List list = new ArrayList();
|
62
|
+
list.add(gu1);
|
63
|
+
list.add(gu2);
|
64
|
+
list.add(gu3);
|
65
|
+
|
66
|
+
|
67
|
+
request.setAttribute("list",list);
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
RequestDispatcher dispatcher = request.getRequestDispatcher("/sample_get1.jsp");
|
72
|
+
dispatcher.forward(request, response);
|
73
|
+
|
74
|
+
|
75
|
+
}
|
76
|
+
|
77
|
+
/**
|
78
|
+
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
79
|
+
*/
|
80
|
+
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
81
|
+
// TODO Auto-generated method stub
|
82
|
+
//doGet(request, response);
|
83
|
+
|
84
|
+
|
85
|
+
}
|
86
|
+
}
|
87
|
+
|
88
|
+
|
89
|
+
☆GetUser.java------------------------------------------------
|
90
|
+
package sample.pg;
|
91
|
+
|
92
|
+
class GetUser{
|
93
|
+
private String id;
|
94
|
+
private String pass;
|
95
|
+
private String name;
|
96
|
+
private String sex;
|
97
|
+
|
98
|
+
public String getId(){
|
99
|
+
return this.id;
|
100
|
+
}
|
101
|
+
public String getPass(){
|
102
|
+
return this.pass;
|
103
|
+
}
|
104
|
+
public String getName(){
|
105
|
+
return this.name;
|
106
|
+
}
|
107
|
+
public String getSex(){
|
108
|
+
return this.sex;
|
109
|
+
}
|
110
|
+
|
111
|
+
public void setId(String id){
|
112
|
+
this.id=id;
|
113
|
+
}
|
114
|
+
public void setPass(String pass){
|
115
|
+
this.pass=pass;
|
116
|
+
}
|
117
|
+
public void setName(String name){
|
118
|
+
this.name=name;
|
119
|
+
}
|
120
|
+
public void setSex(String sex){
|
121
|
+
this.sex=sex;
|
122
|
+
}
|
123
|
+
}
|
124
|
+
|
125
|
+
☆sample_get1.jsp------------------------------------------
|
126
|
+
|
127
|
+
<%@ page contentType="text/html;charset=UTF-8" %>
|
128
|
+
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
|
49
|
-
<
|
129
|
+
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
|
130
|
+
|
131
|
+
|
132
|
+
<!DOCTYPE html">
|
50
133
|
<html>
|
51
134
|
<head>
|
52
|
-
<meta
|
135
|
+
<meta charset="UTF-8">
|
53
136
|
<title>Insert title here</title>
|
54
137
|
</head>
|
55
138
|
<body>
|
56
139
|
<table border="1">
|
57
|
-
<c:forEach var="item" items="list">
|
58
140
|
<tr>
|
141
|
+
<c:forEach var="item" items="${requestScope['list']}">
|
59
|
-
|
142
|
+
<td>${item.getId()} </td>
|
143
|
+
</c:forEach>
|
60
144
|
</tr>
|
61
|
-
</c:forEach>
|
62
145
|
</table>
|
63
146
|
</body>
|
64
|
-
</html>
|
147
|
+
</html>
|
148
|
+
|
149
|
+
|
150
|
+
各ユーザー(gu○)のインスタンスを作り、それを各リストに入れました。
|
151
|
+
中身はID,PASS,NAMEのフィールドになっています。
|
152
|
+
|
153
|
+
これを最終的にJSP側に飛ばし、リストをすべてテーブルタグの間にループさせて表示させたいですがうまくいきません。
|
154
|
+
|
155
|
+
もしかしてJSP側でJAVAで作ったクラスを読み込ませる処理が必要だったりするのでしょうか?
|
156
|
+
JSP側でインスタンスをする処理が必要になってくるのでしょうか?
|
157
|
+
よろしくお願い致します。
|