-
page对象:
代表页面本身,即svrelet的this,类型就是生成的Serlet。 -
application对象:
application 对象可将信息保存在服务器中,直到服务器关闭,否则application对象中保存的信息会在整个应用中都有效。
<html>
<head><title>201819101023 姚雪丽</title></head>
<body>
<h2>application对象</h2>
<%
String serverPath = application.getContextPath();
out.println(serverPath);
application.setAttribute("", "");
%>
</body>
</html>
-
config:
config 对象的主要作用是取得服务器的配置信息。通过 pageConext对象的 getServletConfig() 方法可以获取一个config对象。 -
exception:
exception 对象的作用是显示异常信息,只有在包含 isErrorPage=“true” 的页面中才可以被使用,在一般的JSP页面中使用该对象将无法编译JSP文件。 -
out:
out 对象用于在Web浏览器内输出信息,并且管理应用服务器上的输出缓冲区。 -
pageContext:
pageContext 对象的作用是取得任何范围的参数,可以获取 JSP页面的out、request、reponse、session、application 等对象。 -
requext:
request 对象是 javax.servlet.httpServletRequest类型的对象。
<%@ 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>
<form action="request-receiver.jsp" method="post">
username:<input type="text" name="user"/><br/>
password:<input type="password" name="pwd"/><br/>
<input type="submit" name="登陆"/>
</form>
</body>
</html>
- reponse:
response 代表的是对客户端的响应,主要是将JSP容器处理过的对象传回到客户端。
<%@ 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>
- session:
session 对象是由服务器自动创建的与用户请求相关的对象。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>1111</title>
</head>
<body>
<%
String name = (String)session.getAttribute("name");
String pwd = (String)session.getAttribute("pwd");
out.println("登陆成功");
out.println(name+","+pwd);
System.out.println(session.getId()); //获取当前回话的id
%>
</body>
</html>