gogoWebsite

Web development advanced (XI) how to nest a jsp page in another page

Updated to 1 month ago

How to nest a jsp page in another page

This is often used in doing web pages, some common content can be centralized in a page file, other pages to use these contents only need to include (reference) this common file can be. This is easy to maintain, if there are many web pages, when the general content needs to be modified, only change a file can be, do not need to modify each file individually.

The most typical application such as copyright information in the footer can be placed in a file called, and then other page files can just include this file at the end of the page content.

JSP files need to run on a Java-based server, such as Apache Tomcat.The syntax for the first method of JSP include files is:

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

This directive means: include the page statically, regardless of its content, but whether it is a static page or a dynamic page will first add the content of the page first.

The second way is to use the <jsp:include> action element.

<jsp:include page="" flush="true" />

When the JSP page is requested to introduce the specified file. (Execute first, include later) This tag representation: can dynamically distinguish between dynamic pages loaded in or static pages, for static pages will be directly included in the resource (only the text).

We all know that in the jsp include there are two forms, are

<%@ include file=” ”%>

<jsp:include page=” ” flush=”true”/>

The former is a directive element, the latter a behavioral element. Where exactly will they be used? How will they be used and what is the difference between them? That should be the question that comes to mind for many people when they see it. Take a look below.

Usually we can consider using include when certain parts of the application are the same on all pages (e.g., headers, footers, and navigation bars). 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. Only by understanding the differences in their usage can you understand when to use and how to choose.

<%@ include file=" "%>,jsp's include directive element reads in the content of the specified page. And fuses this content with the original page. (This process is carried out in the translation phase: that is, the jsp is transformed into a servlet.

Here is a description of the translation phase:We know that the jsp page can not be transmitted to the browser as is, all the jsp elements must first be processed by the server. This is done by relaying the jsp page into a servlet and then executing this servlet. The server needs a jsp container to handle the jsp page. jsp container is usually implemented in the form of a servlet , the servlet has been configured to handle all requests for jsp pages .

Jsp container is responsible for the jsp page into a servlet (called jsp page implementation class? JSP Page implementation class), and compile the servlet. these two steps constitute the translation phase.

From this we will know: jsp page is to include the actual content of the page specified by the directive element (that is, code snippets) into the introduction of its jsp page, synthesized into a file by the jsp container will be transformed into a servlet. you can see that this time will produce a temporary class file and a java file.

Theory to theory, the actual operation process will still encounter all kinds of problems. Splitting the code according to the above method results in an error: 500 Internal Server Error!