JSP引擎的内置对象Request对象来获取客户提交的信息

Example3_4.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"

pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Request对象</title>
</head>
<body>
<form action="tree2.jsp" method="post">
<input type="text" name="username" /> <input type="submit" value="提交"
name="submit" />
</form>
</body>

</html>

tree2.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.util.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<br>
<span style="color: blue"> 客户使用的协议是: <%
String protocol = request.getProtocol();
out.println("<span style='color:red'>" + protocol + "</span>");
%>
</span>
<br>
<span style="color: blue">获取接收客户提交信息的页面: <%
String path = request.getServletPath();
out.println("<span style='color:red'>" + path + "</span>");
%></span>
<br>
<span style="color: blue">接收客户提交信息的长度: <%
int length = request.getContentLength();
out.println("<span style='color:red'>" + length + "</span>");
%></span>
<br>
<span style="color: blue">客户提交信息的方式: <%
String method = request.getMethod();
out.println("<span style='color:red'>" + method + "</span>");
%></span>
<br>
<span style="color: blue">获取http头文件中user-agent的值: <%
String header1 = request.getHeader("User-Agent");
out.println("<span style='color:red'>" + header1 + "</span>");
%></span>
<br>
<span style="color: blue">获取http头文件中accept的值: <%
String header2 = request.getHeader("accept");
out.println("<span style='color:red'>" + header2 + "</span>");
%></span>
<br>
<span style="color: blue">获取http头文件中host的值: <%
String header3 = request.getHeader("Host");
out.println("<span style='color:red'>" + header3 + "</span>");
%></span>
<br>
<span style="color: blue">获取http头文件中accept-encoding的值: <%
String header4 = request.getHeader("accept-encoding");
out.println("<span style='color:red'>" + header4 + "</span>");
%></span>
<br>
<span style="color: blue">获取客户的IP地址: <%
String IP = request.getRemoteAddr();
out.println("<span style='color:red'>" + IP + "</span>");
%></span>
<br>
<span style="color: blue">获取客户机的名称: <%
String clientName = request.getRemoteHost();
out.println("<span style='color:red'>" + clientName + "</span>");
%></span>
<br>
<span style="color: blue">获取服务器的名称: <%
String serverName = request.getServerName();
out.println("<span style='color:red'>" + serverName + "</span>");
%></span>
<br>
<span style="color: blue">获取服务器的端口: <%
int serverPort = request.getServerPort();
out.println("<span style='color:red'>" + serverPort + "</span>");
%></span>
<br>
<span style="color: blue">获取客户端提交的所有参数的名字: <%
Enumeration e = request.getParameterNames();
while (e.hasMoreElements()) {
String s = (String) e.nextElement();
out.println("<span style='color:red'>" + s + "</span>");
}
%></span>
<br>
<span style="color: blue">获取头名字的一个枚举: <%
Enumeration enum_headed = request.getHeaderNames();
while (enum_headed.hasMoreElements()) {
String s = (String) enum_headed.nextElement();
out.println("<span style='color:red'>" + s + "</span>");
}
%></span>
<br>
<span style="color: blue">获取头文件中指定头名字的全部值的一个枚举: <%
Enumeration enum_headedValues = request.getHeaders("cookie");
while (enum_headedValues.hasMoreElements()) {
String s = (String) enum_headedValues.nextElement();
out.println("<span style='color:red'>" + s + "</span>");
}
%></span>
<br>
<span style="color: blue">按钮的名字: <%
String buttonName = request.getParameter("submit");
//以独特的字节编码格式读入到一个字节数组内存
//再将该字节数组转换成字符串
%></span>
<br><%=buttonName%>
</body>
</html>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值