Java Web Learning Notes File Inclusion and page layout policy

Source: Internet
Author: User

Use include to prevent pagesCodeRedundant and repetitive, and standardized layout, only one containing statement can be used for code reuse to improve efficiency, as shown below:

1> include command: <% @ include file = "relativeurl" %>, and relativeurl is the applicationProgramPath of another JSP or HTML file. For example, if all pages in the website have a uniform navigation bar head. jsp or script copyright foot. jsp, you can use the include command. That is, the include command is used to implement the blockchain of JSP pages.

The sample code is as follows:

<% @ Pagelanguage = "Java" conenttype = "text/html; charset = UTF-8" %>

<% @ Brief defile = "head. jsp" %>

...

<% @ Shortdefile = "foot. jsp" %>

2> <JSP: Include/> behavior: <JSP: Include page = "relativeurl" Flush = "true"/> attribute page is required and is the relative path of the included file, must be a file in this web application. The value range of the flush attribute is true or false. The default value is false. Set whether to clear the cache before reading the content of the saved file.

The sample code is as follows:

<% @ Pagelanguage = "Java" contenttype = "text/html; charsert = UTF-8" %>

<JSP: includeflush = "true" page = "/head. jsp?> </Jsp: Include>

Here is the text

<JSP: includeflush = "true" page = "/foot. jsp"> </jsp: Include>

 

The difference between the two: although the include command and the include action can contain a file, the principle of the two is different from that of the include action at the time of occurrence. The former is "first include, then compile", which is included in the compilation, includingSource codeWhile the latter includes "run first, then include" at runtime, and only contains the running result. The include action applies to request. getrequestdispatcher ("relativeurl"). Forward (request. Response) to execute the contained file.

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.