<%@ page
language="java"
import="java.io.*"
import="java.text.*"
import="java.util.*"
contentType="text/html;charset=utf-8" %>
<%!
// *********************************************************
// ローカル関数
// *********************************************************
public void outlog( ServletContext app,String message ) {
app.log( String.format("<<JSP>> %s", message ) );
}
public String getData( ServletContext app, HttpServletRequest request,String name ) {
String strGet = request.getParameter(name);
if ( strGet == null ) {
strGet = "";
}
else {
outlog( app, String.format("InputGet:%s", strGet ) );
}
return strGet;
}
%>
<%
// *********************************************************
// 入力値の表示
// GET で setCharacterEncoding を有効にするには
// sever.xml => Connector で useBodyEncodingForURI="true"
// *********************************************************
request.setCharacterEncoding("utf-8"); // 入力値のエンコーディング
// GET 入力
String strGet = getData( application, request, "InputGet" );
// POST 入力
String strPost = request.getParameter("InputPost");
if ( strPost == null ) {
strPost = "";
}
else {
outlog( application, String.format("InputPost:%s", strPost ) );
}
%>
<!DOCTYPE html>
<html>
<head>
<meta content="width=device-width initial-scale=1.0 minimum-scale=1.0 maximum-scale=1.0 user-scalable=no" name="viewport">
<meta charset="UTF-8">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.1/css/bootstrap.css">
<style>
#main {
padding: 30px;
}
pre {
font-size: 24px;
}
</style>
</head>
<body>
<div id="main">
フォーム : GET
<form method="get">
<input type="text" name="InputGet" value="<%= strGet %>">
<input type="submit" name="send" value="GET">
</form>
フォーム : POST
<form method="post">
<input type="text" name="InputPost" value="<%= strPost %>">
<input type="submit" name="send" value="POST">
</form>
<pre>
getdata = <%= strGet %>
postdata = <%= strPost %>
</pre>
</div>
</body>
</html>