内置对象
Request对象
1.获得用户提交的表单信息
<body> <form action = "register" method = "post"> 用户名:<input type = "text" name = "username"><br> 密码:<input type = "password" name = "password"><br> 爱好 : LOL<input type="checkbox" name="hobits" value="lol"> DOTA<input type="checkbox" name="hobits" value="dota"> <br> <input type="submit" value="注册"> </form>
![在这里插入图片描述](https://img-blog.csdnimg.cn/20200915173706429.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L0FJeWluU2lvbg==,size_16,color_FFFFFF,t_70#pic_center)
输入用户名,密码提交用户信息
2.response对象
用于动态响应客户端请示,控制发送给用户的信息,并将动态生成响应。
response.setBufferSize(10000);
response.resetBuffer();
out.print( response.getBufferSize()+"输出缓冲区的大小");
out.print(response.getLocale()+"获取本地化信息");
out.print(response.getCharacterEncoding()+"获取字符编码格式");
out.print(response.getContentType()+"获取响应的类型");
response.setContentLength(100000);
3.<%
pageContext.setAttribute(“name”, “刘宇超”) ;
pageContext.setAttribute(“name1”, “哈哈哈”,PageContext.SESSION_SCOPE) ;
%>
<%
String name = (String) pageContext.getAttribute(“name”) ;
out.write(name) ;
String name1 = (String) session.getAttribute(“name1”) ;
out.write(name1) ;
%>`
4.
使用pageContext的findAttribute方法查找属性值
<%
pageContext.setAttribute("name1", "111");
request.setAttribute("name2", "222");
session.setAttribute("name3", "333");
application.setAttribute("name4", "444");
%>
<%
String refName1 = (String)pageContext.findAttribute("name1");
String refName2 = (String)pageContext.findAttribute("name2");
String refName3 = (String)pageContext.findAttribute("name3");
String refName4 = (String)pageContext.findAttribute("name4");
String refName6 = (String)pageContext.findAttribute("name6");
%>
<body>
<h1>pageContext.findAttribute方法找到的属性值:</h1>
<h3>pageContext:<%=refName1 %></h3>
<h3>request:<%=refName2 %></h3>
<h3>session:<%=refName3 %></h3>
<h3>application:<%=refName4 %></h3>
<h3>不存在的:<%=refName6 %></h3>
<hr>
<h1>EL表达式疯狂输出:</h1>
<h3>pageContext:${name1} </h3>
<h3>request:${name2}</h3>
<h3>session:${name3}</h3>
<h3>application:${name4}</h3>
<h3>不存在的:${name6}</h3
EL表达式语句在执行时,会调用pageContext.findAttribute方法,用标识符为关键字,分别从111、222、333、444四个域中查找相应的对象,找到则返回相应对象,找不到则返回null
5.session对象
session可以在应用程序的Web页面间进行跳转时,保存用户的状态,使整个用户会话一直存在下去,直到关闭浏览器。
out.print(session.getAttribute(""));
out.print(session.getAttributeNames());
out.print(session.getCreationTime());
out.print(session.getId());
out.print(session.getLastAccessedTime());
out.print(session.getMaxInactiveInterval()+"返回最大时间的间隔");