Examples and descriptions of dynamic and static content on JSP pages
I. Static inclusion
This article describes the JSP static inclusion statement, that is, the inclusion operation completed by using the JSP include command.
In JSP, there are two methods to include other files, one is static inclusion, and the other is dynamic inclusion. This article describes static inclusion.
Static inclusion has the same effect as ASP. It includes all contained files to form a large JSP file, which is then compiled by the compiler in a unified manner, generate HTML code.
JSP static statement:
Copy codeThe Code is as follows:
<% @ Include file = "file. jsp" %>
Here, file. jsp is the file to be included. You can use a directory to include the file. It can be a relative directory or an absolute path.
When static JSP inclusion, you need to pay attention to the encoding problem.
In JSP files, we must specify the page contentType GBK, GB2312, UTF-8, etc. in order to enter Chinese in the document. As follows:
Copy codeThe Code is as follows:
<% @ Page language = "java" contentType = "text/html; charset = GBK" pageEncoding = "GBK" %>
However, it is important to note that when this file is statically contained, if its encoding is slightly different from the encoding of the file containing it, an error will be reported. Therefore, if static inclusion is required, make sure that the encoding statements (contentType) of these two files are completely consistent.
Ii. Dynamic inclusion
ASP does not dynamically include this statement. All content is static. In JSP, dynamic and static content are very different.
This article describes the dynamic inclusion in JSP.
Dynamic inclusion in JSP is different from static inclusion. It combines the HTML results of each JSP page and outputs them to the client browser after compiling and executing them separately.
What does it 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, and its logical structure. They are compiled and executed separately. For example, if a outputs "a", B. jsp outputs "B" after execution, and c. jsp outputs "c" after execution, a outputs "abc ".
JSP dynamic Syntax:
JSP dynamic inclusion is not a command, but a tag, as shown below:
Copy codeThe Code is as follows: <jsp: include page = "file. jsp"/>
Or:
Copy codeThe Code is as follows:
<Jsp: include page = "file. jsp">
<Jsp: param name = "p1" vlaue = "v1"/>
</Jsp: include>
There is no essential difference between the above two statements, except that the former is a simple inclusion, while the latter can pass parameters to the contained page. You can use request. getParameter ("parameter name") to obtain the parameter when it is passed to the contained page.
As you know, in asp, if you use the include statement, the included files do not contain parameters. Therefore, asp contains the same static content as jsp.
Static and Dynamic JSP inclusion
<% @ Include file = "check. jsp "%> is include direve ve, that is, your check. all codes in jsp are stored in Login. the location of this statement in jsp, And you directly write the above Code to Login. the same effect in jsp;
<Jsp: include page = "check. jsp "/> is to check. put the HTML code after jsp execution in Login. the corresponding location in jsp, but check. response. redirect ("") or response. addCookie ("") and other response operations will be ignored, that is, the user will not be sent to another page, that is, the jump will not be implemented.
Reference: zhidao.baidu.com/question/41012445.html? Si = 3
The difference between dynamic and static content in java JSP is that dynamic content contains incoming data? Example
Dynamic inclusion refers to the calculation of the webpage to be included, and the calculation result is obtained. Multiple compilations.
Static inclusion is used to block a webpage. Compile only once.
Generally, we use static content at most, because dynamic content is compiled and computed every time it is accessed. This will affect the performance.