zoukankan      html  css  js  c++  java
  • jsp九大内置对象

    ***jsp九大内置对象
    >out(JspWriter):等同于response.getWriter(),用来向客户端发送文本数据
    >config(ServletConfig):对应java 中的ServeltCofig
    >pageContext(PageContext):页面上下文对象
    >exception(Throwable):只有在错误页面中可以使用这个对象
    >request(HttpServletRequest):即HttpServletRequest类的对象
    >response(HttpServletResponse):即HttpServletResponse类的对象
    >application(ServletContext):即ServletContext类的对象
    >session(HttpSession):即HttpSession类的对象,不是每个jsp页面中都可以使用,
    如果在某个jsp页面中设置<%@page = "false" %>,说明这个页面不能使用session

    *这几个内置对象中有很多是极少会被使用的,例如:config,page,exception
    *这九个内置对象有两个不是每个jsp页面都可以使用:exception,session

    *****
    *jsp页面的内容出现在源码的_jspService()方法中,而在_jspService()方法开头部分已经
    创建了9个内置对象
    public void _jspService(HttpServletRequest request, HttpServletResponse response)
    throws java.io.IOException, ServletException {

    PageContext pageContext = null;
    HttpSession session = null;
    ServletContext application = null;
    ServletConfig config = null;
    JspWriter out = null;
    Object page = this;
    JspWriter _jspx_out = null;
    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;

        从这里开始,才是JSP页面的内容
    }…

    ***>pagaContext对象
    在JavaWeb中一共有四个域对象,其中Servlet中可以使用的是request,session,application
    三个对象,而在jsp中可以使用pageContext,request,session,application四个域对象
    pageContext对象时PageContext类型,它的主要功能有:
    >域对象功能
    >代理其他域对象功能
    >获取其他内置对象


    *>域对象功能
    pageContext也是域对象,它的范围是当前页面,它的范围也是四个域对象中最小的
    void setAttribute(String name,Object value);
    void getAttribute(String name,Object value);
    void removeAttribute(String name,Object value);
    *>代理其他域对象功能
    可以使用pageContext来代理其他3个域对象的功能,也就是说可以用pageContext向
    request,session,application对象中存取数据,例如:

    //向pageContext中存储数据
    pageContext.setAttribute("x", "X");
    //向request中存储数据
    pageContext.setAttribute("x", "XX", PageContext.REQUEST_SCOPE);
    //向session中存储数据
    pageContext.setAttribute("x", "XXX", PageContext.SESSION_SCOPE);
    //向application中存储数据
    pageContext.setAttribute("x", "XXXX", PageContext.APPLICATION_SCOPE);

    ** void setAttribute(String name,Object value,int scope):在指定范围中添加数据
    ** Object getAttribute(String name,int Scope):获取指定范围的数据
    ** void removeAttribute(String name,int scope):移除指定范围的数据
    ** Object findAttribute(String name):依次在page,reqeust,session,application范围
    查找名称为name的数据,如果找到就停止查找。

    *>获取其他内置对象
    一个pageContext对象等于所有内置对象,即1个当9个,因为可以使用pageContext获取
    其他8个内置对象
    *JspWriter getOut():获取out内置对象
    *ServletConfig getServletConfig():获取config内置对象
    *Object getPage():获取page内置对象
    *ServletRequest getRequest():获取request内置对象
    *ServletResponse getResponse():获取response内置对象
    *HttpSession getSession():获取session内置对象
    *ServletContext getServletContext():获取application内置对象
    *Exception getException():获取exception内置对象

  • 相关阅读:
    安装JavaJDK没有jre环境的解决办法 错误: C:Program FilesJavajdk-11.0.7jre
    Centos7 安装redis 5.0.8 开机自启动
    某科学的PID算法学习笔记
    数学建模题目和模型汇总(2000-2019 国赛本科组)
    我,不是说了PID要平均值吗?
    私人网盘很难搭建吗?实际上仅需两步!
    Appium+Python
    Appium+Python-模拟手机滑动操作(swipe)
    Appium+Python-模拟手机按键操作
    Appium+Python-元素定位(常用定位)
  • 原文地址:https://www.cnblogs.com/trister/p/4601934.html
Copyright © 2011-2022 走看看