1, what is static import?
Static import refers to the embedding of an external file in the current JSP file, parsing the JSP statement of the page, and including other compilation instructions on the target page.
The static import directives for include use syntax:
Copy Code code as follows:
<% @include file= "Relativeurlspec"%>
Static Import Usage Example include1.jsp:
Copy Code code as follows:
<%@ page contenttype= "text/html; Charset=utf-8 "language=" java "errorpage=" "%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> static include example </title>
<body>
<!--Specify an import page using include compilation-->
<% @include file= "error.jsp"%>
</body>
Where error.jsp is a simple error-handling page, the code is as follows:
Copy Code code as follows:
<%@ page contenttype= "text/html; Charset=utf-8 "language=" java iserrorpage= "true"%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> Error Tips page </title>
<body>
This is an error-handling page </br>
</body>
After you run the static include example under Tomcat, view the generated servlet class to see the following snippet
(View: Under Windows, locate the work folder under the Tomcat installation directory, enter the localhost folder under the Catalina folder, locate the folder where the current project resides, locate the Org directory, and enter the JSP folder under the Apache directory below it, You can see a Include1_jsp.java file, which is the servlet class that the include1.jsp corresponds to the generated. PS: I put this test page under the Webdemo, so my directory is \apache-tomcat-7.0.47\work\catalina\localhost\webdemo\org\apache\jsp
You can see from the box that the static import is the code that contains the page that will contain the page at compile time. It should be noted that the static import will also include the page's compilation instructions also included, if the two-page compilation instructions conflict, then the page will be wrong.
2, what is dynamic import
Dynamic import does not import the compilation instructions for the Include page, but inserts the body content of the imported page into this page only.
Dynamic imported Syntax format:
Copy Code code as follows:
<jsp:include page= "{relativeurl|<%=expression%>}" flush= "true"/>
Or
Copy Code code as follows:
<jsp:include page= "{relativeurl|<%=expression%>}" flush= "true" >
<jsp:param name= "parametername" value= "ParameterValue"/>
</jsp:include>
The Flush property specifies whether the output cache is transferred to the file being imported. If specified as true, it is included in the imported file and, if False, is included in the original file and can only be set to False for JSP1.1 older versions.
For the second syntax format, you can add additional request parameters to the page being imported.
Dynamic Import Example:
We change the above include1.jsp code static import to dynamic import
Copy Code code as follows:
<%@ page contenttype= "text/html; Charset=utf-8 "language=" java "errorpage=" "%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title> static include example </title>
<body>
<!--Specify an import page using include compilation-->
<jsp:include page= "error.jsp"/>
</body>
After compiling to view the generated servlet code, you can see the following paragraphs:
The code in the red box shows that the dynamic import simply uses an include method to insert the content of the target page, rather than incorporating the target page fully into this page.
To sum up, static import and dynamic import have the following three points difference:
1, static import will be imported into the page of the Code fully integrated, two pages into a whole servlet, and dynamic import in the servlet using the Include method to introduce the content of the imported page.
2, the static import of the page to be imported to compile instructions will work, and dynamic import when the page is imported to the compiler instructions are lost, but inserted into the page of the body content.
3, dynamic Import can also add additional parameters. As in the following code mode:
Copy Code code as follows:
<jsp:include page= "{relativeurl|<%=expression%>}" flush= "true" >
<jsp:param name= "parametername" value= "ParameterValue"/>
</jsp:include>