zoukankan      html  css  js  c++  java
  • Jsp 9—— 内置对象

    index.jsp

    <%@page contentType="text/html; charset=UTF-8"%>
    
    <%--
        关于JSP中的九大内置对象
            内置对象                        完整类名
            -------------------------------------------
            pageContext                    javax.servlet.jsp.PageContext                            页面范围【页面上下文】
            request                        javax.servlet.http.HttpServletRequest                    请求范围
            session                        javax.servlet.http.HttpSession                            会话范围
            application                    javax.servlet.ServletContext                            应用范围
            
            response                    javax.servlet.http.HttpServletResponse                    响应对象
            out                            javax.servlet.jsp.JspWriter                                标准输出流
            
            config                        javax.servlet.ServletConfig                                Servlet配置信息对象
                
            exception                    java.lang.Throwable                                        异常引用(isErrorPage="true")
            
            page                        javax.servlet.http.HttpServlet  (page = this)            很少用
    --%>
    
    <%--
        主要研究下JSP中的四个作用域对象/范围对象:
            pageContext < request < session < application
            
            pageContext : 在同一个JSP页面中共享数据,不能跨JSP页面
            request : 在同一个请求中共享数据  【使用较多】
            session : 在同一个会话中共享数据  【使用较多】
            application : 所有用户共享的数据可以放到应用范围中
    --%>
    
    <%
        pageContext.setAttribute("pageContext" , "pageContextData");
        request.setAttribute("request","requestData");
        session.setAttribute("session","sessionData");
        application.setAttribute("application","applicationData");
    %>
    
    <%=pageContext.getAttribute("pageContext") %>
    <br>
    <%=request.getAttribute("request") %>
    <br>
    <%=session.getAttribute("session") %>
    <br>
    <%=application.getAttribute("application") %>
    
    
    <%--
    <jsp:forward page="/index2.jsp"></jsp:forward>
     --%>
    
    <%
        response.sendRedirect(request.getContextPath() + "/index2.jsp");
    %>

     

    index2.jsp

    <%@page contentType="text/html; charset=UTF-8"%>
    
    <%=pageContext.getAttribute("pageContext") %>
    <br>
    <%=request.getAttribute("request") %>
    <br>
    <%=session.getAttribute("session") %>
    <br>
    <%=application.getAttribute("application") %>
    
    <%--
        pageContext只能在同一个JSP页面中共享数据。范围是最小的。
        通过pageContext这个页面上下文对象,可以获取当前页面中的其它对象。
    --%>
    <%=pageContext.getRequest() %>
    <%=pageContext.getSession() %>
    <%=pageContext.getServletContext() %>
    <%=pageContext.getServletConfig() %>

     直接访问index2.jsp

     

    转载请注明出处:https://www.cnblogs.com/stu-jyj3621
  • 相关阅读:
    定义通用类型,便于移植和32位、64位的编译
    映射密码的加密,解密以及暴力破解
    位移密码的加密,解密以及暴力破解
    TCP三次握手和四次挥手通俗理解
    git常用命令
    pip及npm换源
    win10安装Docker并换国内源
    搜索引擎工作原理
    wsgi_uwsgi_nginx理论知识
    课程全文检索接口
  • 原文地址:https://www.cnblogs.com/stu-jyj3621/p/14380688.html
Copyright © 2011-2022 走看看