使用request对象获取客户端的有关信息:
input039.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'input039.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<form action="showinfo.jsp" method="post"> //输入两个数据
数据1:<input type="text" name="shuju1"><br>
数据2:<input type="text" name="shuju2"><br>
<input type="submit" value="提交">
</form>
</body>
</html>
运行结果:
showinfo.jsp
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'showinfo.jsp' starting page</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<font color="blue">提交表单信息:</font><br> //获取客户端信息并显示
输入的第一个数据是:<%=request.getParameter("shuju1") %><br>
输入的第二个数据是:<%=request.getParameter("shuju2") %><br><br>
<font color="red">客户端信息:</font><br>
客户端协议名和版本号:<%=request.getProtocol() %><br>
客户机名:<%=request.getRemoteHost() %><br>
客户机的IP地址:<%=request.getRemoteAddr() %><br>
客户提交信息的长度:<%=request.getContentLength() %><br>
客户提交信息的方式:<%=request.getMethod() %><br>
HTTP头文件的Host值:<%=request.getHeader("Host") %><br>
服务器名:<%=request.getServerName() %><br>
服务器端口号:<%=request.getServerPort() %><br>
接受客户提交信息的页面:<%=request.getServletPath() %><br>
</body>
</html>
运行结果: