jsp的四大域对象

<%--
  Created by IntelliJ IDEA.
  User: pengshengwang
  Date: 2022/1/13
  Time: 11:02
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<html>
  <head>
  <base href="<%=basePath%>"/>
    <title>$Title$</title>
  </head>
  <body>

  <%
//      pageContext
      pageContext.setAttribute("name","pagecontext");
      String name1 = (String) pageContext.getAttribute("name");
//      request
      request.setAttribute("name","request");
      String name2 = (String)request.getAttribute("name");
//      session
      session.setAttribute("name","session");
      String name3 = (String)session.getAttribute("name");
//      application
      application.setAttribute("name","application");
      String name4 = (String)application.getAttribute("name");
//      方法二
      ServletContext servletContext = pageContext.getServletContext();
      if(servletContext==application){
          out.print("servletContext就是application");
      }

//      pageContext.setAttribute(String str,object o,int i);
//      i可以是1234分别对应从上到下四个
      pageContext.setAttribute("name","第二个构造",1);

//      也是从上到下开始查询
      pageContext.findAttribute("name");

  %>

  <%--引入到一个jsp--%>
  <jsp:include page="head.jsp">
      <jsp:param name="name" value="tom"/>
  </jsp:include>

  <%--t跳转到另一个jsp--%>
  <jsp:forward page="head.jsp">
      <jsp:param name="name" value="tom"/>
  </jsp:forward>
  <%--动态引入--%>
  $END$
  </body>
</html>


上一篇:Koltin44,安卓开发权威指南


下一篇:Kotlin协程概览 (一)