Dynamic inclusion and static inclusion examples and introduction of JSP pages _jsp programming

Source: Internet
Author: User

One, Static contains

This article describes the JSP static include statement, which is the inclusion operation that is accomplished using the JSP's include directives.
In JSP, there are two ways to contain other files, one being static and the other dynamic. This article describes the static inclusions.

The so-called static contains, with the ASP contains the same effect, will be all included in the file, the first static included in the composition of a large JSP file, and then after the compiler unified compilation, generate HTML code.

The JSP statically contained statements are:

Copy Code code as follows:

<%@ include file= "file.jsp"%>

The file.jsp here is the file to include, which can be included in the directory, can be a relative directory, can be an absolute path.

JSP static contains, you need to pay attention to the problem of coding.

In the JSP file, we must specify the page contenttype for GBK, GB2312, UTF-8, etc. to enter Chinese in the document. As follows:

Copy Code code as follows:

<%@ page language= "java" contenttype= "text/html; CHARSET=GBK "pageencoding=" GBK "%>

It is important to note, however, that when this file is statically contained, its encoding will be an error if it is inconsistent with the encoding of the file containing it. So, if you want to include it statically, make sure that the two-file encoding (i.e. contenttype) is fully consistent.

Second, dynamic inclusion

This is not dynamically included in the ASP, and all of the inclusions are statically contained. In JSP, there is a big difference between dynamic inclusion and static inclusion.
This article says a dynamic inclusion in JSP.

The dynamic inclusion in the JSP is different from the static inclusion, which is a way to combine the HTML results of each JSP page into the client browser.

What does that mean?

such as a.jsp, including the b.jsp and c.jsp. A.JSP cannot share variables and functions set in b.jsp and c.jsp, nor can they share their logical structure. Each is compiled and executed separately. such as a after the output "a", b.jsp after the output "B", c.jsp execution after the output "C", then eventually output "abc".

The syntax that the JSP dynamically contains:

The JSP dynamically contains an instruction that is not used, but rather a label that is used as follows:

Copy Code code as follows:
<jsp:include page= "file.jsp"/>

Or:
Copy Code code as follows:

<jsp:include page= "file.jsp" >
<jsp:param name= "P1" vlaue= "v1"/>
</jsp:include>

There is no essential difference between the two statements, but the former is a simple inclusion, and the latter can pass parameters to the included page. parameter is passed to the included page, it can be obtained by using the Request.getparameter ("parameter name").

As you know, in ASP, if you use the include include statement, the included file is not allowed with parameters. So, the inclusion in the ASP is the same as the static contained in the JSP.

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.