zoukankan      html  css  js  c++  java
  • JSP静态包含和动态包含的区别

    jsp动态包含和静态包含实现的内容一样,但是实现的方式不同。

    jsp静态包含<%@ include file="" %>


    创建include1.jsp和include2.jsp

      include1.jsp代码

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
        
    <%@ include file="include2.jsp"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
        this is include page 1
    </body>
    </html>

      include2.jsp代

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
        this is include page 2
    </body>
    </html>

    运行结果:

      如果是静态包含,则只会生成一个java文件

      

      原因:因为include1.jsp要把include2.jsp内容完全引用,所有include1.jsp会和include2.jsp合成一个jsp,然后翻译成.java文件,最后编译运行。

    jsp动态包含<jsp:include page=""></jsp:include>

    创建Newfile1.jsp和NewFile2.jsp

    Newfile1.jsp代码

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
        <jsp:include page="/NewFile2.jsp"></jsp:include>
        this is newFile1
    </body>
    </html>

    Newfile2.jsp代码

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
        pageEncoding="ISO-8859-1"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="ISO-8859-1">
    <title>Insert title here</title>
    </head>
    <body>
        this is newFile2
    </body>
    </html>

    运行结果:

    如果是动态包含,则会生成两个.java文件

     原因是:因为是先访问NewFile1.jsp,所以先翻译成NewFile1_jsp.java,然后编译运行时发现代码,于是返回访问NewFile2.jsp,然后翻译NewFile2_jsp.java,最后编译将内容和在一起。

    附上一张图便于理解:

    每天学习一些东西,将重要的写博,日积月累!!!

    如果大佬发现又错误或者说的不透彻,请留言指出!!!

     

  • 相关阅读:
    jQuery笔记(1)
    [bzoj 1878][SDOI2009]HH的项链
    [bzoj 1968][Ahoi2005]COMMON 约数研究
    [bzoj 1899][ZJOI2004]lunch 午餐
    [bzoj 1090][SCOI2003]字符串折叠
    CodeForces 1029E div3
    [bzoj 1270][BeijingWc2008]雷涛的小猫
    [bzoj 1260][CQOI 2007]涂色paint
    [AtCoder ARC101D/ABC107D] Median of Medians
    [luogu 1070]道路游戏(NOIP2009T4)
  • 原文地址:https://www.cnblogs.com/yangxiao-/p/12001905.html
Copyright © 2011-2022 走看看