There are many sayings on the Internet:
Differences between static and dynamic JSP content:
- Dynamic include is implemented using JSP: include action.
- <JSP: Include page = "embedded ded. jsp"
- Flush = "true"/> it always checks for changes in the contained files. It is suitable for inclusion of dynamic pages and
- And can contain parameters
- Static include is implemented by using the include pseudo code and will not check the changes in the contained files. It is applicable to packages.
- Static pages included: <% @ include file = "included.htm" %>
However, I have verified that such a statement is not completely correct. At least the dynamic <JSP: inlude> command can contain dynamic pages.
I personally think the difference is:
1 <JSP: inlude> the same page can contain as many lines as possible, no matter what content on this page, as long as the page itself is legal, the <% @ include> pseudocommand can contain only one variable and method defined on the page.
(This is consistent with the second compilation method)
2. dynamically include the pages included and included when the request arrives. If both pages are JSP pages, the class files and java files corresponding to the two pages will be generated. Static inclusion only generates Java files and class files that contain pages.
3. Dynamic inclusion refers to the process of converting a request to a contained page when a request contains a page. In this case, the contained page is compiled. Static inclusion is used to compile the inclusion page when a request contains a page. during compilation, the static page inclusion pseudo code copies the content of the contained page to the contained page for compilation.
4. The <JSP: inlude> command contains the path of the contained file on the page, but the static file contains the path of the contained file. (This is clearly explained by Sun Xin in "Java Web in-depth explanation)
5. When referencing a range attribute of a contained page, the dynamically contained command is location-related. That is, the attribute value set for referencing the included page before the <JSP: Include> command is invalid. However, static inclusion does not differentiate the locations of contained commands. It is valid to reference the properties set on the contained page before containing commands.
The two have the same points:
1. You can interact with each other. attributes in the request range object include pages and included pages.
2. When the included page references a property that contains the page settings, both of them are related to setting the value that contains the range property in the page. That is, the property is valid only when it contains the range property set before the page is included.
The Code is as follows: contains the page: index. jsp
<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "UTF-8" buffer = "23kb" %>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Title> This is 'index. jsp '</title>
</Head>
<Body>
This is the inclusion page <br/>
<% -- Static include prefix reference property set on the included page -- %>
$ {Name} static include the attributes set by the Pre-Reference included page <br/>
<% -- Include page setting attributes -- %>
<% Request. setattribute ("PWS", "456"); %>
<% -- <% @ Include file = "myjsp. jsp" %> the variable defined in myjsp. jsp cannot be repeatedly included. -- %>
<% -- %> <% @ Include file = "myjsp. jsp" %>
$ {Name} references a property after a static page is included. <br/>
<% -- No variables are defined in you. jsp, so you can include them again -- %>
$ {Wangzhanming} <br/>
<% @ Include file = "you. jsp" %>
<% @ Include file = "you. jsp" %>
$ {Wangzhanming} <br/>
<JSP: Include page = "myjsp. jsp"> </jsp: Include>
<JSP: Include page = "myjsp. jsp"> </jsp: Include>
<% Request. setattribute ("PWS", "lyx"); %>
<% -- Repeated include -- %>
<JSP: Include page = "myjsp. jsp"> </jsp: Include>
<% @ Include file = "you. jsp" %>
$ {Name} <br/>
</Body>
</Html>
Set the variable inclusion page: myjsp. jsp
<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "UTF-8" %>
<% -- Define variable -- %>
<%
String Path = request. getcontextpath ();
String basepath = request. getscheme () + ": //" + request. getservername () + ":" + request. getserverport () + path + "/";
%>
<! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en">
<HTML>
<Head>
<Base href = "<% = basepath %>">
<Title> This is 'myjsp. jput' </title>
<Meta http-equiv = "Pragma" content = "no-Cache">
<Meta http-equiv = "cache-control" content = "no-Cache">
<Meta http-equiv = "expires" content = "0">
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "Description" content = "this is my page">
<! --
<LINK rel = "stylesheet" type = "text/CSS" href = "styles.css">
-->
</Head>
<Body>
This is the definition variable inclusion page <br/>
<% -- Set the range attribute on the included page -- %>
<% Request. setattribute ("name", "wzm"); %>
$ {Name} <br>
<% -- Referenced on the contained page Attributes -- %>
$ {PWS} <br/>
</Body>
</Html>
Include page with no variable settings: You. jsp
<% @ Page Language = "Java" Import = "Java. util. *" pageencoding = "UTF-8" %>
<HTML>
<Head>
<Title> This is 'you. js' </title>
<Meta http-equiv = "Pragma" content = "no-Cache">
<Meta http-equiv = "cache-control" content = "no-Cache">
<Meta http-equiv = "expires" content = "0">
<Meta http-equiv = "keywords" content = "keyword1, keyword2, keyword3">
<Meta http-equiv = "Description" content = "this is my page">
<! --
<LINK rel = "stylesheet" type = "text/CSS" href = "styles.css">
-->
</Head>
<Body>
This is an include page that does not define variables <br>
<% Request. setattribute ("wangzhanming", "haoren"); %>
$ {Wangzhanming} <br/>
$ {PWS} <br/>
</Body>
</Html>