Two forms and introductions of include

Source: Internet
Author: User
Tags introductions

Another form and difference of include
Let's briefly say the two forms of include:
<% include file= ""%>: for static inclusion (load)
<jsp:include page= "" flush= "true"/>: for dynamic inclusion (loading)

Simply explain the static inclusions and dynamic inclusions:
Static include: The JSP compiler compiles the time already contains the corresponding file, generates a Java_servlet, the corresponding servlet file contains the included page, and then Javac compiled into a class file, when the JVM is running, a page can not be passed the parameter ( is equivalent to sending himself a reference), meaningless.

Dynamic inclusion: When the JSP compiler compiles, loading the page and being clamped on the page will be parsed into two java_servlet files, Javac compiler will compile two times, generate two class files and then in the process of running the JVM, this time contains files to call the included class file (Note: JSP tags need to close themselves, do not forget to close the slash)

Here is an analysis diagram of my own drawing:

To give you some examples of reference:

<! DOCTYPE html>
<meta charset= "UTF-8" >
<title>jsp:include</title>
<body bgcolor= "White" >
<font color= "Red" >
<%@ include file= "file name"%>
<%= request + "--1--" + "<br>"%>
<jsp:include page= "file name" flush= "true"/>
<%= request + "--1--" + "<br/>"%>

<jsp:include page= "filename? username= ' 123 '" flush= "true"/>

</font>
</body>

As you can see from the example above, because the build is two different servlet files--Different class---> so each servlet has its own request object, Not the same one. But the first one is to generate a servlet so it's the same request.

<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "
pageencoding= "Utf-8"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>TestBar.jsp</title>
<body>
<table width= "100%" >
<tr><td><%@ include file= "file name"%></td></tr>
<%=request.getparameter ("username")%>
<tr><td><% out.println ("<p> This is the user display area </p>");%></td></tr>
</table>

</body>

The above example shows that after two source files are generated, it is the same page, and then the same request is used on this page and the same request object is received.

Two forms and introductions of include

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.