以下は、各環境変数を取得して、ブラウザ画面に表示するサーバサイドプログラムのサンプルです。
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class PrintEnv extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
String strServerName = request.getServerName();
String strServerProtocol = request.getProtocol();
String strRequestMethod = request.getMethod();
String strPathInfo = request.getPathInfo();
String strScriptName = request.getServletPath();
String strQueryString = request.getQueryString();
String strRemoteAddr = request.getRemoteAddr();
String strRemoteHost = request.getRemoteHost();
int numContentLength = request.getContentLength();
String strHttpUserAgent = request.getHeader("User-Agent");
String strHttpReferer = request.getHeader("Referer");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("SERVER_NAME = " + strServerName + "<br>");
out.println("SERVER_PROTOCOL = " + strServerProtocol + "<br>");
out.println("REQUEST_METHOD = " + strRequestMethod + "<br>");
out.println("PATH_INFO = " + strPathInfo + "<br>");
out.println("SCRIPT_NAME = " + strScriptName + "<br>");
out.println("QUERY_STRING = " + strQueryString + "<br>");
out.println("REMOTE_ADDR = " + strRemoteAddr + "<br>");
out.println("REMOTE_HOST = " + strRemoteHost + "<br>");
out.println("CONTENT_LENGTH = " + numContentLength + "<br>");
out.println("HTTP_USER_AGENT = " + strHttpUserAgent + "<br>");
out.println("HTTP_REFERER = " + strHttpReferer + "<br>");
out.println("</body>");
out.println("</html>");
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}
}
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class PrintEnv extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
response.setContentType("text/html");
String strServerName = request.getServerName();
String strServerProtocol = request.getProtocol();
String strRequestMethod = request.getMethod();
String strPathInfo = request.getPathInfo();
String strScriptName = request.getServletPath();
String strQueryString = request.getQueryString();
String strRemoteAddr = request.getRemoteAddr();
String strRemoteHost = request.getRemoteHost();
int numContentLength = request.getContentLength();
String strHttpUserAgent = request.getHeader("User-Agent");
String strHttpReferer = request.getHeader("Referer");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("SERVER_NAME = " + strServerName + "<br>");
out.println("SERVER_PROTOCOL = " + strServerProtocol + "<br>");
out.println("REQUEST_METHOD = " + strRequestMethod + "<br>");
out.println("PATH_INFO = " + strPathInfo + "<br>");
out.println("SCRIPT_NAME = " + strScriptName + "<br>");
out.println("QUERY_STRING = " + strQueryString + "<br>");
out.println("REMOTE_ADDR = " + strRemoteAddr + "<br>");
out.println("REMOTE_HOST = " + strRemoteHost + "<br>");
out.println("CONTENT_LENGTH = " + numContentLength + "<br>");
out.println("HTTP_USER_AGENT = " + strHttpUserAgent + "<br>");
out.println("HTTP_REFERER = " + strHttpReferer + "<br>");
out.println("</body>");
out.println("</html>");
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
doGet(request, response);
}
}