九大内置对象【经典面试题】
Servlet中的对象【request,response,session,servletConfig,servletContext】
继承了httpServlet
Jsp—>servlet
继承了HttpJspBase
我们看到只有八个
还有一个exception
这些内置对象现在我们一般用不到
九个内置对象简单介绍如下
Application
servletContext[作用域]【全局对象】
Config
sevletConfig [获取当前页面的jspServlet的配置参数]
Out
【jspWrite–servlet里面的PrinterWrite】【jsp的打印对象】
Page
Jsp独有的,用来描述页面的
PageContext
Jsp独有的
Request
【请求对象】【httpServletRequest】
Response
【响应对象】httpServletResponse
Session
httpSession 【会话】
Exception
【异常对象】【处理页面发生异常时的对象】【pageContext.getException()】
JSP四大作用域
Servlet【request,session,servletContext】
Jsp:
pageContext 作用在当前页面
Request 作用在请求中
Session 作用在会话中
Application 作用在整个服务器上
作用域范围
PageContext < request < session < appliction
<%
session.setAttribute("run", "这是会话作用域");
application.setAttribute("run", "我是全局作用域");
pageContext.setAttribute("run", "这是当前页面的作用域");
request.setAttribute("run", "我是请求作用域");
%>
<div>${run}</div>
先从作用范围小的里面取值,娶不到再去大范围去取
若果要取出指定范围的值使用 scope
<%
session.setAttribute("run", "这是会话作用域");
application.setAttribute("run", "我是全局作用域");
pageContext.setAttribute("run", "这是当前页面的作用域");
request.setAttribute("run", "我是请求作用域");
%>
<div>${run}</div>
<div>${sessionScope.run }</div>
<div>${pageScope.run}</div>