1、内置对象request:
<form action="request-receiver.jsp">
username:<input type="text" name="user"/><br/>
password:<input type="password" name="pwd"/><br/>
<input type="submit" name="登陆"/>
</form>
request对象代表了电脑客户端的请求信息,是接受信息传送到电脑服务器的数据。
2、内置对象out:
<%
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) ;
%>
out 对象用于在Web浏览器内输出信息,并且管理应用服务器上的输出缓冲区。
3、内置对象resonpse:
<%@ 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>Insert title here</title>
</head>
<body>
不好意思,登陆失败。
</body>
</html>
response 代表的是对客户端的响应,主要是负责将电脑处理过的对象在传回到客户端。
4、session(会话):
<%
String name = (String)session.getAttribute("name");
String pwd = (String)session.getAttribute("pwd");
out.println("登陆成功");
out.println(name+","+pwd);
System.out.println(session.getId()); //获取当前回话的id
%>
session对象是服务器自动创建的与用户请求对象,来保存用户信息的。
5、内置对象pageContext:
<form action="<%=request.getContextPath()%>/session.jsp" method="post">
username:<input type="text" name="user"/><br/>
password:<input type="password" name="pwd"/><br/>
<input type="submit" name="登陆"/>
</form>
<h2>pageContext对象</h2>
//通过PageContext上下文对象获取当前页面的其他内置对象
pageContext.getRequest();
pageContext.getResponse();
pageContext.getSession();
pageContext.getOut();
String path = request.getContextPath();
out.println("当前上下文的绝对路径:"+path);
%>
pageContext 对象是取得范围的参数,可获取其他内置对象,比如out、request等。
6、内置对象application:
<h2>application对象</h2>
<%
//一个应用程序只有一个application对象
//在服务器启动时创建,到服务器关闭时销毁
//所有客户端共享一份
String serverPath = application.getContextPath();//获取当前应用程序的路径
//向application对象添加数据
application.setAttribute("", "");
%>
application对象是将信息保存到服务器当中,一直到服务器关闭。
7、内置对象exception:
<%
int[] num = {9,2,3,2,8};
for(int i =0;i<=num.length;i++){
out.println(num[i]);
}
%>
exception 对象是显示异常信息。
8、内置对象config
主要是取得服务器的配置信息
9、内置对象page
主要处理请求。