質問編集履歴
1
追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -40,7 +40,7 @@
|
|
40
40
|
|
41
41
|
```Java
|
42
42
|
|
43
|
-
package section23
|
43
|
+
package section232;
|
44
44
|
|
45
45
|
|
46
46
|
|
@@ -64,13 +64,13 @@
|
|
64
64
|
|
65
65
|
/**
|
66
66
|
|
67
|
-
* Servlet implementation class
|
67
|
+
* Servlet implementation class GetRequestParameterJPServlet
|
68
68
|
|
69
69
|
*/
|
70
70
|
|
71
|
-
@WebServlet("/
|
71
|
+
@WebServlet("/GetRequestParameterJPServlet")
|
72
|
-
|
72
|
+
|
73
|
-
public class
|
73
|
+
public class GetRequestParameterJPServlet extends HttpServlet {
|
74
74
|
|
75
75
|
private static final long serialVersionUID = 1L;
|
76
76
|
|
@@ -82,7 +82,7 @@
|
|
82
82
|
|
83
83
|
*/
|
84
84
|
|
85
|
-
public
|
85
|
+
public GetRequestParameterJPServlet() {
|
86
86
|
|
87
87
|
super();
|
88
88
|
|
@@ -98,7 +98,27 @@
|
|
98
98
|
|
99
99
|
*/
|
100
100
|
|
101
|
+
protected void doGet(HttpServletRequest request, HttpServletResponse response)
|
102
|
+
|
103
|
+
throws ServletException, IOException {
|
104
|
+
|
105
|
+
// TODO Auto-generated method stub
|
106
|
+
|
107
|
+
response.getWriter().append("Served at: ").append(request.getContextPath());
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
/**
|
114
|
+
|
115
|
+
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
116
|
+
|
117
|
+
*/
|
118
|
+
|
119
|
+
// POSTリクエストを処理するメソッド
|
120
|
+
|
101
|
-
protected void do
|
121
|
+
protected void doPost(
|
102
122
|
|
103
123
|
HttpServletRequest request,
|
104
124
|
|
@@ -114,13 +134,35 @@
|
|
114
134
|
|
115
135
|
|
116
136
|
|
137
|
+
// リクエストパラメータの文字コードを設定
|
138
|
+
|
139
|
+
request.setCharacterEncoding("utf-8");
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
// パラメータの取得
|
144
|
+
|
145
|
+
String name = request.getParameter("name");
|
146
|
+
|
147
|
+
String age = request.getParameter("age");
|
148
|
+
|
149
|
+
String address = request.getParameter("address");
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
// HTML形式の内容を出力する
|
154
|
+
|
117
155
|
PrintWriter out = response.getWriter();
|
118
156
|
|
119
157
|
out.write("<html><body>");
|
120
158
|
|
121
|
-
out.write("<meta http-equiv=\"text/html; charset=utf-8\">");
|
122
|
-
|
123
|
-
out.write("
|
159
|
+
out.write("POSTパラメータ<br>");
|
160
|
+
|
161
|
+
out.write("name:" + name + "<br>");
|
162
|
+
|
163
|
+
out.write("age :" + age + "<br>");
|
164
|
+
|
165
|
+
out.write("address:" + address + "<br>");
|
124
166
|
|
125
167
|
out.write("</body></html>");
|
126
168
|
|
@@ -130,26 +172,6 @@
|
|
130
172
|
|
131
173
|
}
|
132
174
|
|
133
|
-
|
134
|
-
|
135
|
-
/**
|
136
|
-
|
137
|
-
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
|
138
|
-
|
139
|
-
*/
|
140
|
-
|
141
|
-
protected void doPost(HttpServletRequest request, HttpServletResponse response)
|
142
|
-
|
143
|
-
throws ServletException, IOException {
|
144
|
-
|
145
|
-
// TODO Auto-generated method stub
|
146
|
-
|
147
|
-
doGet(request, response);
|
148
|
-
|
149
|
-
}
|
150
|
-
|
151
|
-
|
152
|
-
|
153
175
|
}
|
154
176
|
|
155
177
|
```
|
@@ -171,3 +193,23 @@
|
|
171
193
|
|
172
194
|
|
173
195
|
![イメージ説明](6f38dc75bdfcd26d1fab8a4937441385.png)
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
【追記❶】
|
200
|
+
|
201
|
+
サーブレットクラスの場合は
|
202
|
+
|
203
|
+
/アプリケーション名/URLパターン
|
204
|
+
|
205
|
+
|
206
|
+
|
207
|
+
のようなので
|
208
|
+
|
209
|
+
|
210
|
+
|
211
|
+
/example/GetRequestParameterJPServlet
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
のはずですが、同じく404と出ます。ご教授お願いします。
|