回顾:Servlect常用的对象,过滤器,监听器。

ServletConfig:对象获得静态数据

ServletContext对象:获取共享静态数据,获取共享动态数据,获取共享文件数据.

HttpServletResponse 对象HttpServlet调用HttpResponse的有关方法,生成响应数据

HttpServletRequest对象:HttpServlet调用HttpResponse的有关方法,生成响应数据,用于服务器上接收浏览器发送过来的数据信息

Cookie对象,对象Session对象。程序把每个用户的数据以Cookie/Session的形式写给用户各自的浏览器。

Filter:过滤器,阻止非法网站的访问。

Listener:

实现了特定接口的类为监听器,用来监听另一个Java类的方法调用或者属性改变;** 当被监听的对象发生了方法调用或者属性改变后,监听器的对应方法就会立即执行。

JSP内置对象

到服务器中的work文件中去看看


打开文件中的Out_jsp_java

/** Generated by the Jasper component of Apache Tomcat* Version: Apache Tomcat/9.0.53* Generated at: 2021-11-11 09:23:21 UTC* Note: The last modified time of this file was set to*       the last modified time of the source file after*       generation to assist with modification tracking.*/
package org.apache.jsp;import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.util.Calendar;public final class Out_jsp extends org.apache.jasper.runtime.HttpJspBaseimplements org.apache.jasper.runtime.JspSourceDependent,org.apache.jasper.runtime.JspSourceImports {private static final javax.servlet.jsp.JspFactory _jspxFactory =javax.servlet.jsp.JspFactory.getDefaultFactory();private static java.util.Map<java.lang.String,java.lang.Long> _jspx_dependants;private static final java.util.Set<java.lang.String> _jspx_imports_packages;private static final java.util.Set<java.lang.String> _jspx_imports_classes;static {_jspx_imports_packages = new java.util.HashSet<>();_jspx_imports_packages.add("javax.servlet");_jspx_imports_packages.add("javax.servlet.http");_jspx_imports_packages.add("javax.servlet.jsp");_jspx_imports_classes = new java.util.HashSet<>();_jspx_imports_classes.add("java.util.Calendar");}private volatile javax.el.ExpressionFactory _el_expressionfactory;private volatile org.apache.tomcat.InstanceManager _jsp_instancemanager;public java.util.Map<java.lang.String,java.lang.Long> getDependants() {return _jspx_dependants;}public java.util.Set<java.lang.String> getPackageImports() {return _jspx_imports_packages;}public java.util.Set<java.lang.String> getClassImports() {return _jspx_imports_classes;}public javax.el.ExpressionFactory _jsp_getExpressionFactory() {if (_el_expressionfactory == null) {synchronized (this) {if (_el_expressionfactory == null) {_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();}}}return _el_expressionfactory;}public org.apache.tomcat.InstanceManager _jsp_getInstanceManager() {if (_jsp_instancemanager == null) {synchronized (this) {if (_jsp_instancemanager == null) {_jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());}}}return _jsp_instancemanager;}public void _jspInit() {}public void _jspDestroy() {}public void _jspService(final javax.servlet.http.HttpServletRequest request, final javax.servlet.http.HttpServletResponse response)throws java.io.IOException, javax.servlet.ServletException {if (!javax.servlet.DispatcherType.ERROR.equals(request.getDispatcherType())) {final java.lang.String _jspx_method = request.getMethod();if ("OPTIONS".equals(_jspx_method)) {response.setHeader("Allow","GET, HEAD, POST, OPTIONS");return;}if (!"GET".equals(_jspx_method) && !"POST".equals(_jspx_method) && !"HEAD".equals(_jspx_method)) {response.setHeader("Allow","GET, HEAD, POST, OPTIONS");response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, "JSP 只允许 GET、POST 或 HEAD。Jasper 还允许 OPTIONS");return;}}final javax.servlet.jsp.PageContext pageContext;javax.servlet.http.HttpSession session = null;final javax.servlet.ServletContext application;final javax.servlet.ServletConfig config;javax.servlet.jsp.JspWriter out = null;final java.lang.Object page = this;javax.servlet.jsp.JspWriter _jspx_out = null;javax.servlet.jsp.PageContext _jspx_page_context = null;try {response.setContentType("text/html; charset=UTF-8");pageContext = _jspxFactory.getPageContext(this, request, response,null, true, 8192, true);_jspx_page_context = pageContext;application = pageContext.getServletContext();config = pageContext.getServletConfig();session = pageContext.getSession();out = pageContext.getOut();_jspx_out = out;out.write("\r\n");out.write("\r\n");out.write("<!DOCTYPE html>\r\n");out.write("<html>\r\n");out.write("<head>\r\n");out.write("<meta charset=\"UTF-8\">\r\n");out.write("<title>Out对象</title>\r\n");out.write("</head>\r\n");out.write("<body>\r\n");out.write('\r');out.write('\n');//创建日历类Calendar  calendar =Calendar.getInstance();int AM_PM=calendar.get(calendar.AM_PM);if(AM_PM==calendar.AM){out.write("<h1 style=' color:red'>上午时间</h1>");}else if(AM_PM==calendar.PM){out.write("<h1 style=' color:green'>下午时间</h1>");}out.write("\r\n");out.write("\r\n");out.write("<h1>\r\n");out.write("四大作用域(有四个对象)有四个对象共享数据\r\n");out.write("<hr>\r\n");out.write("seesion   浏览器不切\r\n");out.write("<hr>\r\n");out.write("application  服务器不关闭\r\n");out.write("<hr>\r\n");out.write("request:请求转发跳转页面的情况,只能两个页面共享数据\r\n");out.write("<hr>\r\n");out.write("pageContext:该对象中只能页面自己用\r\n");out.write("<hr>\r\n");out.write("才能用setAttribute的方法\r\n");out.write("<hr>\r\n");out.write("将四作用域排序\r\n");out.write("<hr>\r\n");out.write("pageContext  request  seesion   application \r\n");out.write("</h1>\r\n");out.write("</body>\r\n");out.write("</html>");} catch (java.lang.Throwable t) {if (!(t instanceof javax.servlet.jsp.SkipPageException)){out = _jspx_out;if (out != null && out.getBufferSize() != 0)try {if (response.isCommitted()) {out.flush();} else {out.clearBuffer();}} catch (java.io.IOException e) {}if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);else throw new ServletException(t);}} finally {_jspxFactory.releasePageContext(_jspx_page_context);}}
}

从上面代码中我们可以找到这些对象

 final javax.servlet.jsp.PageContext pageContext;
    javax.servlet.http.HttpSession session = null;
    final javax.servlet.ServletContext application;
    final javax.servlet.ServletConfig config;
    javax.servlet.jsp.JspWriter out = null;
    final java.lang.Object page = this;
    javax.servlet.jsp.JspWriter _jspx_out = null;
    javax.servlet.jsp.PageContext _jspx_page_context = null;

什么是内置对象,在jsp文件运行后,会翻译成一个Servlect类,
在这个类中可以直接调用的对象


九大内置对象的核心表格

out        JspWriter   将文本信息输出浏览器
request HttpServletRequest   获得浏览器发送来的数据
respone  HttpServletRequest  回复浏览器请求
seesion HttpSeesion          在不换浏览器放信息    
exception Throwable    异常报错
page Servlect(this)   jsp翻译出来类的对象
config     ServlectConfig           静态数据
application ServlectContext    共享数据
pageContext  PageContextjsp      管理者引出对象

   

        final javax.servlet.jsp.PageContext pageContext;
    javax.servlet.http.HttpSession session = null;
    final javax.servlet.ServletContext application;
    final javax.servlet.ServletConfig config;
    javax.servlet.jsp.JspWriter out = null;
    final java.lang.Object page = this;
    javax.servlet.jsp.JspWriter _jspx_out = null;
    javax.servlet.jsp.PageContext _jspx_page_context = null;

四大作用域(有四个对象)有四个对象共享数据
seesion   浏览器不切
application  服务器不关闭
request:请求转发跳转页面的情况,只能两个页面共享数据
pageContext:该对象中只能页面自己用
才能用setAttribute的方法
将四作用域排序

pageContext<request<seesion<application 

这些对象应用的方式和Servlect相似

回顾jsp一些重要标签和指令

<%! %>:用于在jsp文件中定义全局变量和方法
<%= %>:用于在jsp文件中将java中的数据结果显示在html文本中
<% %>:用于在jsp文件中执行多行代码,包括if,while,for,创建对象等等
<%-- --%>:用于在jsp文件中的注释
<%@ %>:用于在jsp文件中操作指令代码

Jsp常用的三大指令:page,include,taglib

page指令的常用属性:
import:导入所需要的包
language:当前jsp页面里面可以嵌套的语言
contenType:设置响应流的编码,及通知浏览器用什么编码打开
pageEncoding:设置页面的编码
extends:声明当前jsp的页面继承于哪个类
session:设置jsp页面是否可以使用session内置对象
buffer:设置jsp页面的流的缓冲区大小
autoFlush:是否自动刷新
isELIgnored:是否忽略el表达式
errorPage:当前jsp页面出现异常的时候要跳转到的jsp页面
isErrorPage:当前jsp页面是否是一个错误页面

运行页面结果

 

代码区

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1 style="color: red;">欢迎来到a.jsp文件</h1><%String a=(String)request.getAttribute("a");out.write("通过请求转发获得的数据为"+a);
%>
</body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body><%-- application,    ServlectContext 对象八ServlectContext      共享数据  整个项目中只会有一个对象
tomcat 服务器 一关闭 数据释放 数据的共享更服务器相关 --%><%
//获得静态数据String info =application.getInitParameter("a");out.write(info);//动态数据out.write("<hr>");application.setAttribute("c", "我是动态数据");out.write((String)application.getAttribute("c"));
%></body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%--     config 第七个对象        类名ServlectConfig            增加静态数据   --%>
<%
String name = config.getServletName();
out.write(name);%>
</body>
</html>

<%@ page language="java"  errorPage="error.jsp"    contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<style type="text/css">
*{
font-size: 29px;
color: red;
}</style>
</head>
<body><%-- <%int a=100/0; %> --%>
<hr><% int [] arr =new int [3];
System.out.println(arr[3]);
%>
<hr>
<%-- <%
Integer i =new Integer ("abd");
%> --%>
<hr></body>
</html>

<%@ page language="java"    isErrorPage="true"  contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h1>
除数不能为0:用户
</h1><h1><%= exception.getMessage() %></h1>
<h3><%=exception.toString() %></h3>
<h4><%=exception.hashCode()%></h3></body>
</html>

<%@page import="java.util.Calendar"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Out对象</title>
</head>
<body>
<%--<!-- jsp九大对象之一:out对象 对应的类  JspWripiter -->  --%>
<%
//创建日历类Calendar  calendar =Calendar.getInstance();int AM_PM=calendar.get(calendar.AM_PM);if(AM_PM==calendar.AM){out.write("<h1 style=' color:red'>上午时间</h1>");}else if(AM_PM==calendar.PM){out.write("<h1 style=' color:green'>下午时间</h1>");}%><h1>
四大作用域(有四个对象)有四个对象共享数据
<hr>
seesion   浏览器不切
<hr>
application  服务器不关闭
<hr>
request:请求转发跳转页面的情况,只能两个页面共享数据
<hr>
pageContext:该对象中只能页面自己用
<hr>
才能用setAttribute的方法
<hr>
将四作用域排序
<hr>
pageContext  request  seesion   application
</h1>
</body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%--对象 page 对象 六  page,      Servlect(this)          jsp翻译出来类的对象   --%>
<%
out.write((page.equals(this)?"page是当前对象":"page不是当前对象"));
%>
</body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Request对象</title>
</head>
<body>
<%-- jsp九大对象 request 类名HttpSevlectRequest --%>
<% String name=request.getParameter("name");out.write("<h1>我收到浏览器发送的数据为</h1>"+name);out.write("<h2 style='color:red'>http://localhost:8080/Day_13/Request.jsp?name=xao</h2>");//携带数据跳转页面request.setAttribute("a", "apple");request.getRequestDispatcher("a.jsp").forward(request, response);%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%-- jsp九大内置对象  Respone对象三类名 HttpServlectRespone--%>
<h1 style="color: red;">Respone.jsp</h1><%response.sendRedirect("Out.jsp");out.write("Hellow JSP");%>
</body>
</html>

<%@ page language="java" contentType="text/html; charset=UTF-8"pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%----  对象四Session  HttpSession   Session放的数据为同已过浏览器服务器 所有Servlect 和 jsp都能共享Session里数据 --%>
<%session.setAttribute("b", "我是session对象的定义b");session.setAttribute("c", "我是session对象的定义c");out.write((String)session.getAttribute("b"));out.write((String)session.getAttribute("c"));%>
</body>
</html>

2022年欢迎来到Jsp编程第二课:JSP核心九大内置对象相关推荐

  1. Jsp (Java Server Pages)相关知识九大内置对象和四大作用域

    一.初识JSP Jsp页面的组成:静态内容.指令.表达式.小脚本.声明.标准动作.注释等元素构成 Url:统一资源定位符 Url组成:协议.主机名(包括端口号).路径 1.注释的方式: 1.HTML注 ...

  2. JSP九大内置对象和四个作用域

    在学习JSP的时候,首先就要先了解JSP的内置对象,什么是内置对象呢?内置对象也叫隐含对象,就是不需要预先声明就可以在脚本代码和表达式中随意使用.而这样的内置对象在JSP中一共有九个以及四个作用域,在 ...

  3. 创建线程的几种方式?JSP的九大内置对象及作用分别是什么?servlet的生命周期及常用方法?转发和重定向区别?ajax书写方式及内部主要参数都有哪些

    文章目录 1 , 创建线程的几种方式? 问题扩展: 2 ,JSP的九大内置对象及作用分别是什么? (1) 问题分析: (2) 核心答案讲解: 1.request对象 2.response对象 3.se ...

  4. 面试之JSP九大内置对象和JSP四大作用域

    jsp 九大内置对象和其作用详解 JSP中一共预先定义了9个这样的对象,分别为:request.response.session.application.out.pagecontext.config. ...

  5. Java Web(五) JSP详解(四大作用域九大内置对象等)

    前面讲解了Servlet,了解了Servlet的继承结构,生命周期等,并且在其中的ServletConfig和ServletContext对象有了一些比较详细的了解,但是我们会发现在Servlet中编 ...

  6. JSP九大内置对象(转载)

    JSP中一共预先定义了9个这样的对象,分别为:request.response.session.application.out.pagecontext.config.page.exception 1. ...

  7. Jsp学习总结(1)——JSP九大内置对象和四种属性范围解读

    一.四种属性范围 1.1.在JSP中提供了四种属性保存范围 page:在一个页面内保存属性,跳转之后无效 request:在一次服务请求范围内,服务器跳转后依然有效 session:-在一次会话范围内 ...

  8. jsp四大作用域和九大内置对象

    jsp是运行在服务端的程序 JSP有九个内置对象(又叫隐含对象),不需要预先声明就可以在脚本代码和表达式中随意使用 JSP九大内置对象分为四类: 输入输出对象:out对象.response对象.req ...

  9. JSP中四大作用域和九大内置对象

    文章目录 九大内置对象 一.out对象 二.request对象 三.response对象 四.config对象 五.session对象 六.application对象 七.page对象 八.pageC ...

最新文章

  1. MySQL共有data和redo的后果
  2. 阻塞、非阻塞与同步、异步的区别
  3. vue/return-in-computed-property Enforce that a return statement is present in computed property
  4. navicat 结构同步会加锁吗_被柜员怠慢的张小波,真的会永久地转走几个亿的结构性存款吗?...
  5. [cogs347]地震
  6. python羊车门问题_「羊车门」经典概率题中不换门选中车的概率是多少?
  7. win10管理凌乱桌面_用于管理凌乱的开源存储库的命令行技巧
  8. 关于c语言的符号常量以下叙述中正确的是,关于C语言的符号常量,以下叙述中正确的是( )...
  9. ruby require
  10. HALCON 21.11:深度学习笔记---模型(8)
  11. python sys模块_Python sys模块
  12. 【干货】GRU神经网络
  13. 每一个写博客的程序猿,都应该被温柔对待
  14. 蓝桥杯C语言基础训练答案,蓝桥杯c语言答案.doc
  15. SketchUp:SketchUp草图大师经典案例之实现柜子、书桌等设计
  16. BootStrap之导航条navigationBar
  17. 美规Homekit插座
  18. CC++数组练习题(头歌)朋友圈点赞
  19. 《Web安全之机器学习入门》笔记:第七章 7.5朴素贝叶斯检测WebShell(二)
  20. AS 5637.1跟AS 3837是什么关系?

热门文章

  1. STM32——三原色
  2. word图文混排复制到eWebEditor图片不显示
  3. GC参数解析 UseSerialGC、UseParNewGC、UseParallelGC、UseConcMarkSweepGC
  4. 中国顶尖“黑客”团队:一半是历年高考状元
  5. ArcGIS:按数值提取栅格区域
  6. html面试题(一)--html css js
  7. 时间格式24小时制和12小时制
  8. Qt5 学习之路及嵌入式开发教程11:Qt5标准输入对话框类及QSlider控件
  9. string.Compare用法
  10. android音乐播放器实现,Android实现简单音乐播放器(MediaPlayer)