01.
<%@ page
02.
language=
"java"
03.
import
=
"java.io.*"
04.
import
=
"java.text.*"
05.
import
=
"java.util.*"
06.
contentType=
"text/html;charset=utf-8"
%>
07.
<%!
08.
09.
10.
11.
public
void
outlog( ServletContext app,String message ) {
12.
13.
app.log( String.format(
"<<JSP>> %s"
, message ) );
14.
15.
}
16.
public
String getData( ServletContext app, HttpServletRequest request,String name ) {
17.
18.
String strGet = request.getParameter(name);
19.
if
( strGet ==
null
) {
20.
strGet =
""
;
21.
}
22.
else
{
23.
outlog( app, String.format(
"InputGet:%s"
, strGet ) );
24.
}
25.
26.
return
strGet;
27.
}
28.
%>
29.
<%
30.
31.
32.
33.
34.
35.
request.setCharacterEncoding(
"utf-8"
);
36.
37.
38.
String strGet = getData( application, request,
"InputGet"
);
39.
40.
41.
String strPost = request.getParameter(
"InputPost"
);
42.
if
( strPost ==
null
) {
43.
strPost =
""
;
44.
}
45.
else
{
46.
outlog( application, String.format(
"InputPost:%s"
, strPost ) );
47.
}
48.
49.
%>
50.
<!DOCTYPE html>
51.
<html>
52.
<head>
53.
<meta content=
"width=device-width initial-scale=1.0 minimum-scale=1.0 maximum-scale=1.0 user-scalable=no"
name=
"viewport"
>
54.
<meta charset=
"UTF-8"
>
55.
<link rel=
"stylesheet"
href=
"https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css"
>
56.
57.
<style>
58.
#main {
59.
padding: 30px;
60.
}
61.
62.
pre {
63.
font-size: 24px;
64.
}
65.
</style>
66.
</head>
67.
<body>
68.
<div id=
"main"
>
69.
70.
フォーム : GET
71.
<form method=
"get"
>
72.
<input type=
"text"
name=
"InputGet"
value=
"<%= strGet %>"
>
73.
<input type=
"submit"
name=
"send"
value=
"GET"
>
74.
</form>
75.
76.
フォーム : POST
77.
<form method=
"post"
>
78.
<input type=
"text"
name=
"InputPost"
value=
"<%= strPost %>"
>
79.
<input type=
"submit"
name=
"send"
value=
"POST"
>
80.
</form>
81.
82.
<pre>
83.
84.
getdata = <%= strGet %>
85.
postdata = <%= strPost %>
86.
87.
</pre>
88.
89.
</div>
90.
</body>
91.
</html>