JSP page:
COMMON.JSPF file
If you want to introduce a JSPF file (incurred) into a JSP page, only the "@include" instruction can be introduced, the contents of the JSPF file can be parsed and the instructions in the JSPF file will be executed;
If used <jsp:include> introduced, the contents of the JSPF file are not compiled, it directly contains the contents of the JSPF, that is, the JSP instructions and tags in the JSPF file will not be executed
For example:
<jsp:include page= "XX.JSPF" flush= "true" ></jsp:include>
With JSP dynamic inclusion of this JSPF file after the page display content is not compiled directly to the source code is included in.
Problem Analysis:
JSPF is not the default extension of the JSP Servlet (Tomcat 5.0.28/servlet 2.4/jsp 2.0) like JSP, and the JSP engine does not compile it as a JSP file after dynamically including JSPF with a JSP.
If you are using a Tomcat server, you need to add a conf/web.xml under Tomcat
<!--The mappings for the JSP servlet - <servlet-mapping> <Servlet-name>Jsp</Servlet-name> <Url-pattern>*.jsp</Url-pattern> <Url-pattern>*.jspx</Url-pattern>
<url-pattern>*.jspf</url-pattern>//Add the Url-pattern so that the JSPF extension is also a file processed by the JSP servlet
</servlet-mapping>
If you use a resin server, you need to <servlet-mapping url-pattern= ' *.JSPF ' servlet-name= ' jsp '/> in resin.conf in resin
In this way, the JSP engine is dynamically included in JSP to compile it as a JSP file.
However, if the static inclusion (@include) does not have to do as the configuration can be compiled, why the static inclusion of the file can be, the specific reason can be see the dynamic inclusion of JSP and the difference between the static include file: http://blog.csdn.net/itautomn/article/ details/1635726
Note: It is not recommended to introduce the JSPF type file in, because editing Java code on the JSPF type file does not have JSP admin hints, it is inconvenient to maintain, and the introduction of JSPF type files has no advantage but adds complexity to the configuration. Of course the introduction of the JSPF component (remember there is a jspf.jar), because this JSPF non-JSPF.
<% @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 td> |
|
introduction content |
| <%@ include file= "relativeuri"%> |
translation phase |
static text (HTML, JSP), fused with the JSP page before it was converted to a servlet |
| <jsp:include page= "relativeuri" flush= "True/false"/> |
request processing phase |
|
Personal understanding: <%@ 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.
JSPF, JSP little note