Examples and descriptions of dynamic and static inclusion of JSP pages

  • 2020-12-07 04:10:11
  • OfStack

1. Static inclusion

This article describes the JSP static include statement, which is an include operation performed using the include instruction of JSP.
In JSP, there are two ways to include other files, one static and one dynamic. This article describes static inclusion.

The so-called static inclusion is the same effect as the inclusion in ASP, that is, all the included files are included statically first to form a large JSP file, and then compiled by compiler system 1 to generate HTML code.

JSP static contains the following statements:


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

file. jsp is the file to be included. It can be included using a directory, either relative or absolute.

When JSP is statically included, you need to pay attention to coding issues.

In the JSP file, we must specify contentType of the page as GBK, GB2312, ES30en-8, etc. To enter Chinese in the document. As follows:


<%@ page language="java" contentType="text/html; charset=GBK" pageEncoding="GBK" %>

But it's important to note here that when this file is statically included, its encoding will report an error if it's 1 dot different from the encoding of the file that contains it. Therefore, if you want to include them statically, the 1 must encode the two files in the 1 sentence (contentType) to ensure that they are completely 1.

2. Dynamic inclusion

There is no dynamic inclusion in ASP; all inclusions are static. In JSP, dynamic inclusion is very different from static inclusion.
This article describes the dynamic inclusion in JSP.

Dynamic inclusion in JSP is different from static inclusion. It is a way to combine the HTML results executed by each JSP page after it is compiled and executed separately and output to the client browser.

What does that mean?

For example, a. jsp contains b. jsp and c. jsp. a. jsp cannot share the variables and functions set in b. jsp and c. jsp, nor its logical structure. Each is compiled and executed separately. For example, a prints "a", ES66en.jsp prints "b", c.jsp prints "c", then you end up with "abc".

JSP dynamic contains syntax:

JSP dynamically contains not one instruction used, but one tag used, as follows:

<jsp:include page="file.jsp" />

Or:

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

There is no essential difference between the two statements above, except that the former is a simple inclusion, while the latter can pass parameters to the included page. When parameters are passed to the included page, they can be obtained by using request.getParameter (" parameter name ").

You know that in asp, if you use the include include statement, you cannot include arguments on the included file. Therefore, inclusion in asp is the same as static inclusion in jsp.


Related articles: