<% @include ...> and the difference between the <jsp:include....> directive
Include directive:
During the translation phase (the stage of translating a JSP page into a servlet), include reads the contents of the specified page and blends the content with the original page
<%@ include file= "header.html"%>
The introduced page can contain only static content (such as HTML), or it can be a normal JSP page. The main page and the introduced pages are fused together (the imported pages are just the most common text to fuse, not the dynamic content), and the fused full page is converted into a servlet as a whole.
This means that the homepage and the page being introduced share all the page scope data. Therefore, if a variable is declared in the main page and a variable with the same name is declared in a page that is introduced, then the translation phase will cause an error because the combined page cannot be compiled.
A common use of the include directive is to introduce public declarations that are required for all pages of an application.
The JSP specification recommends that when you introduce JSP pages using the include directive, it is best to use a different file name extension because they are generally not complete and legitimate pages, such as: You can use these alternative file extensions:. JSPF or. JSF.
When the referenced page changes, the container may not react immediately.
<jsp:include>
Directives are used to introduce additional resources at run time.
<jsp:include page= "navigation.jsp"/>
This instruction is executed at the request processing stage rather than in the translation phase. The behavior is not to introduce the actual content of the specified page, it introduces the answer resulting from executing the ingestion page, which means that you can specify any Web resource that can produce a text answer. The JSP container is invoked with an internal function call to invoke the specified resource. As a result, these introduced resources can help with the original request, so these resources can access all objects within the scope of the request, as well as all the request parameters. Note, however, that it cannot access any page scope properties or script variables declared in the main page.
<c:import> behavior is the same as <jsp:include>, and it can also introduce data from external sources, such as different Web applications, or a ftpfuwq.
So you should use <c:import> instead of <jsp:include>.
When the referenced page changes, the new version will be put into use immediately.
the direct difference between include and <jsp:include> behavior
syntax |
execution time |
What to introduce |
<%@ include file= "relativeuri"%> |
translation phase |
static text (HTML, JSP) and merge with him before the JSP page is converted to a servlet |
<jsp:include page= "relativeuri" flush= "True/false"/> ; |
request processing phase |
Execute page or servlet-generated answer text |
Summary: <%@ include file%> is the introduction of the file and the current file together into a servlet file to parse. <jsp:include page> is a servlet file that generates two different servlet files in the current file and introduces the incoming files in a dynamic invocation of the current file.
<jsp:include page> and <%@ include file%> differences