<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import= "java.util.* "%>
<!DOCTYPE html>
<!--
-->
<html>
<head>
<meta charset="UTF-8" content=" text/html charset=UTF-8 " >
<title>request实训</title>
</head>
<body>
<%
// setAttribute(String name ,Object obj) 用于为request对象设置属性 name 属性名 obj 属性值
request.setAttribute("name","测试用例用户名");
request.setAttribute("password","测试用例密码");
request.setAttribute("mail","454565@qq.com");
// removeAttribute( name ) 用于删除请求中的一个属性值
request.removeAttribute("password");
//用于返回request对象保持的所有属性值
//其结果集是一个 Enumeration实例 Enumeration枚举
Enumeration e=request.getAttributeNames();
String attrName;
//遍历所有结果 遍历枚举的一种方法
while(e.hasMoreElements()){
// nextElement() 此方法用于从枚举中获取元素。 .toString()转换为字符串
attrName=e.nextElement().toString();
//输出 getAttribute(attrName) 用于返回name指定request对象的属性值 若不存在指定的属性 返回null
out.print(attrName+"="+request.getAttribute(attrName)+"<br>");
}
// 设置编码格式
request.setCharacterEncoding("ISO-8859-1");
%>
<hr>
编码方式
<%=request.getCharacterEncoding() %>
<br>
请求大小
<%=request.getContentLength() %>
<br>
传送数据方式
<%=request.getMethod() %>
<br>
协议
<%=request.getProtocol() %>
<br>
客户端地址
<%=request.getRemoteAddr() %>
<br>
客户端名称
<%=request.getRemoteHost() %>
<br>
客户端端口
<%=request.getRemotePort() %>
<br>
服务器名称
<%=request.getServerName() %>
<br>
服务器端口
<%=request.getServerPort() %>
<br>
</body>
</html>
JSP:request对象
最新推荐文章于 2024-04-03 15:11:49 发布