Static JSP inclusion <% @ include %>
Now let's take a look at the JSP static include command: <% @ include %>
Create a project testinclude
Then add the file:
Index. jsp:
<%@ page language="java"import="java.util.*" pageEncoding="ISO-8859-1"%>
Curdate: (without a suffix)
<p>curDate: <%=new Date()%></p> <!-- curDate -->
Curdate. jsp:
<p>curDate.jsp: <%=new Date()%></p> <!—curDate.jsp-->
Curdate.html:
<p>curDate.html: <%=newDate()%></p> <!—curDate.html -->
View results:HTTP: /localhost: 8080/testinclude/index. jsp
View its source code:
View the Tomcat working directory:
View the index_jsp.java file:
/** Generated by the Jasper component of Apache Tomcat * version: Apache Tomcat/7.0.22 * generated at: 2011-11-04 11:17:58 UTC * Note: the last modified time of this file was set to * The Last Modified Time of the source file after * generation to assist with modification tracking. */............ Skipped here ..... Try {response. setcontenttype ("text/html; charset = ISO-8859-1"); pagecontext = _ jspxfactory. getpagecontext (this, request, response, null, true, 8192, true); _ jspx_page_context = pagecontext; application = pagecontext. getservletcontext (); Config = pagecontext. getservletconfig (); Session = pagecontext. getsession (); out = pagecontext. getout (); _ jspx_out = out; out. write ("\ r \ n"); out. write ("<HTML> \ r \ n "); Out. write ("<body> \ r \ n"); out. write ("\ t"); out. write ("<p> curdate:"); out. print (new date (); out. write ("</P> <! -- Curdate --> "); out. write ("\ r \ n"); out. write ("\ t"); out. write ("<p> curdate. JSP: "); out. print (new date (); out. write ("</P> <! -- Curdate --> "); out. write ("\ r \ n"); out. write ("\ t"); out. write ("<p> curdate.html:"); out. print (new date (); out. write ("</P> <! -- Curdate.html --> "); out. write ("\ r \ n"); out. write ("\ t <p> This is user's area </P> \ r \ n"); out. write ("</body> \ r \ n"); out. write ("
Analysis summary:
Only index is compiled in the Tomcat working directory. the JSP file, curdate.jsphas not been generated. Java file, and then compared with .html and files without a suffix, the content is similar, so this static include command is actually irrelevant to the format of the included file, only in this article, therefore, it can be inferred that the "include" action requires an index. JSP is converted. before Java (servlet), you only need to include the target file in index. in JSP, simply replace the original commands...
So static include <% @ include % >== text replacement
PS:
Directive (Compilation instruction) is equivalent to the command format during compilation: <% @ directive attribute = "property value" %> All commands in this format are executed during compilation, instead of running at runtime.