<jsp:include page= "" > and <%@ include file= ""%> Difference Summary

Source: Internet
Author: User

<jsp:include page= "" > and <%@ include file= ""%> Difference Summary

1:<jsp:include page= "top.jsp": First, the Java script and JSP directives in top.jsp are executed before the top.jsp page is added to the reference page.

2:<%@ include file= "top.jsp"%> static reads: The entire page of top.jsp is read into the reference page without parsing (either a script or an instruction) and then parsed with the reference page (that is, the script and instructions are started).

3: The difference: In fact, the top of the two is the difference, but it is necessary to note that the <%@ include file= ""%> when the page can no longer be referenced by other page labels and page instructions, or it will conflict

We all know that there are two forms of include in JSP: the include directive, <%@ include file= ""%> and include actions: <jsp:include page= "" flush= "true"/ >
The former is the instruction element, the latter is the behavior element. Where exactly are they going to be used? How to use and what is the difference between them? This should be a problem many people see when they think about it. Let's take a look below.
Typically, when you have the same parts of all the pages in your application (for example, headings, footers, and navigation bars), we can consider using include. Specifically when to use <%@ include file= ""%>, and when to use <jsp:include page= "" flush= "true"/>. This form. The first thing to understand is the difference between them. It is only by understanding the differences in their usage that we understand when to use and how to choose.

The most important difference between the two: JSP directive <%@ include file= ""%>, is the introduction of the JSP and the original JSP fused together, and this fusion process is carried out in the translation phase.

Why do I need a translation phase? We know that the JSP page is not sent to the client intact, because the client browsing the JSP page does not need to install the Java Virtual machine, the client machine can not read the JSP, it can read only HTML, JavaScript (of course, there are other, such as: applets, Flex, Axtivex, and so on, but those all need to download the appropriate client resolver, which requires the servlet Engine (for example, Tomcat) to handle all the JSP elements. This is done by turning the JSP page into a servlet and then executing the servlet. The server needs a JSP container to process the JSP pages. The JSP container is usually implemented as a servlet, which is configured to handle all requests to the JSP page.

The JSP container is responsible for translating the JSP page into a servlet and compiling the servlet. These two steps constitute the translation phase.

The content of the servlet output after JSP translation is what the client browser can recognize, HTML, JavaScript, and so on, the servlet uses the JspWriter object output to output these HTML, JavaScript. If you go through the JSP compiled servlet code, you'll find something very interesting, such as struts <logic:iterator> tags, which are translated into do{}while () statements to implement loops. If we write <bean:write> in <logic:iterator> inside, there will be a similar _jspx_meth_bean_write_2 inside the Do (_jspx_th_logic_iterate_0 , _jspx_page_context) method invocation. That explains everything.

From this we know that the JSP page is the actual content (that is, the code snippet) of the page specified by the Include directive element (<%@ include file= ""%>) to the JSP page in which it was introduced, and the JSP container transforms it into a servlet after the composition of a file. You can see that a temporary class file and a servlet source file are generated. The action element (<jsp:include page= ""/>) is introduced during the request processing phase and is generated by the JSP container with two temporary class files and two servlet original files. The result of the servlet output is the output of the JspWriter object, not the source code of the JSP.

<jsp:include page= "" > and <%@ include file= ""%> Difference Summary

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.