JSP:request对象

<%@ 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>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值