直接上代码,代码中有解释说明
<%@ 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>jsp中9大内置对象演示(内置对象又叫隐藏对象,隐含对象,隐式对象,9个内置对象全部为jsp保留字)</title>
<link rel="stylesheet" type="text/css" href="body.css">
<link rel="stylesheet" type="text/css" href="mark.css">
<link rel="stylesheet" type="text/css" href="input2.css">
</head>
<body>
<%
//jsp内置对象不需要使用者声明创建,由容器维护和管理
//9个隐藏对象
/*
错误对象
exception
*/
/*
输入/输出对象
request(既可以归为输入/输出对象,又可以归为作用域通信对象)
response
out
*/
/*
作用域通信对象
page(既可以归为作用域通信对象,又可以归为servlet对象)
request(既可以归为输入/输出对象,又可以归为作用域通信对象)
session
application
pageContext
*/
/*
servlet对象
page(既可以归为作用域通信对象,又可以归为servlet对象)
config
*/
HttpSession mySession = pageContext.getSession();
mySession.setAttribute("message", "hello 世界!");
out.print("mySession.getAttribute = " + mySession.getAttribute("message") + "<br>");
out.print("session.getAttribute = " + session.getAttribute("message") + "<br>");
out.print("session==mySession结果:" + (session==mySession) + "<br>");
out.print("config.getServletName() = " + config.getServletName() + "<br>");
out.print("config.getInitParameter() = " + config.getInitParameter("userName") + "<br>");
out.print("<h2>servlet的url后面带参数type=" + request.getParameter("type") + "</h2>");
out.print("<h2>servlet的url后面带参数age=" + request.getParameter("age") + "</h2>");
%>
<%="config.getInitParameter() = " + "<hr>" + config.getInitParameter("userName") + "<hr>" %>
<a href="hello?type=1668899&age=15">我是超链接,测试访问servlet的时候,url后面带参数</a>
</body>
</html>