java web中request对象(下)

request对象中的setAttribute方法的使用

意思是在这里保存了一个名字叫做password的密码 他的值为123456

在下面使用getAttribute方法取出password的值,在网页中即显示password的值

getContentType方法用于得到请求体的MIME类型,getProtocol用于得到协议类型及版本号,getServerName可以得到服务器主机名

getServerPort用于得到服务器的端口号,request.getContentLength可以得到请求文件的长度,request.getRemoteAddr可以得到服务器的ip地址

 request.getRealPath可以得到请求的真实路径,request.getContextPath可以得到请求的上下文路径

接下来编码进行演示

网页显示结果

原文地址:https://www.cnblogs.com/liuliuyiming/p/7718308.html