Static JSP inclusion

Source: Internet
Author: User
Tags apache tomcat

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.

 

 

 

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.