JavaWeb Knowledge Collection (4)-jsp command

jsp instruction

<%@ page ... %><!--page指令-->

<%@include file=""%><!--include指令-->

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><!--taglib指令-->

The difference between the two methods of include:

<body>
<%--include指令  将两个页面合二为一--%>
<%@include file="common/header.jsp"%>
<h1>页面中间</h1>
<%@include file="common/footer.jsp"%>
<hr>
<%--jsp标签库  本质还是三个--%>
<jsp:include page="/common/header.jsp"></jsp:include>
<h1>页面中间</h1>
<jsp:include page="/common/footer.jsp"></jsp:include>
</body>

Source code analysis: the code in _jspService

out.write("\r\n");
      out.write("\r\n");
      out.write("<html>\r\n");
      out.write("<head>\r\n");
      out.write("    <title>Title</title>\r\n");
      out.write("</head>\r\n");
      out.write("<body>\r\n");
      out.write('\r');
      out.write('\n');
      out.write("\r\n");
      out.write("\r\n");
      out.write("<html>\r\n");
      out.write("<head>\r\n");
      out.write("    <title>header</title>\r\n");
      out.write("</head>\r\n");
      out.write("<body>\r\n");
//include指令方法
      /*out.write("<h1>我是header</h1>\r\n");
      out.write("</body>\r\n");
      out.write("</html>\r\n");
      out.write("\r\n");
      out.write("<h1>页面中间</h1>\r\n");
      out.write("\r\n");
      out.write("\r\n");
      out.write("<html>\r\n");
      out.write("<head>\r\n");
      out.write("    <title>footer</title>\r\n");
      out.write("</head>\r\n");
      out.write("<body>\r\n");
      out.write("<h1>我是footer</h1>\r\n");*/
      out.write("</body>\r\n");
      out.write("</html>\r\n");
      out.write("\r\n");
      out.write("<hr>\r\n");
      out.write('\r');
      out.write('\n');
//jsp标签库方法   通过引用,引用的对象如下静态代码块
      /*org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "common/header.jsp", out, false);
      out.write("\r\n");
      out.write("<h1>页面中间</h1>\r\n");
      org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "common/footer.jsp", out, false);*/
      out.write("\r\n");
      out.write("\r\n");
      out.write("</body>\r\n");
      out.write("</html>\r\n");

The static code block referenced by the jsp tag library method. This static code block is in the class and not in the _jspService method

static {
    
    
    _jspx_dependants = new java.util.HashMap<java.lang.String,java.lang.Long>(2);
    _jspx_dependants.put("/common/header.jsp", Long.valueOf(1611294179577L));
    _jspx_dependants.put("/common/footer.jsp", Long.valueOf(1611294179662L));
  }

Nine built-in objects

pageContext  存数据
request 存数据
response
session 存数据
out
page
config [servletConfig]
application [servletContext] 存数据
excepition

If there is something wrong, please point it out and make progress together!

Guess you like

Origin blog.csdn.net/weixin_45734378/article/details/112999408