JS we are in the process of doing the procedure, it is often the case that in a project you will find that there are many frames of the page that are basically the same, but the contents are different, and, as a general rule, we might use the include statement to present the framework content and then reference the frames in each page. But this creates a problem, if my frame changes, what should I do? For instance, a index.jsp may contain head.jsp and foot.jsp. Other pages also contain these two jsps. But if I have a navigation bar code in index.jsp, and I want to refer to each page instead of adding it to the head.jsp, do we add the navigation bar code to each page? I don't think I would have done that. Because there is a better way to solve this problem. That is to adopt the template page.
Template The principle of the page, in fact, is to write a servlet to achieve the page jump, and then configure the web.xml inside the servlet, so that you want to use the template of this class of JSP files, through the servlet to deal with, so that they all go to the template page can be. Then include the content pages of these pages in the template page.
Concrete practice, as long as write a template.jsp as a template page, a Templatedispatch.java as a jump class can be. Then, at the time of the call, point directly to the servlet, and add a parameter that explains which content page to use. Write a simple example as follows:
template.jsp
=====================================
<% page contenttype= "text/html; charset=gb2312 "%>
<%@ include file= "head.jsp"%>
<%= (String) request.getattribute ("Body")%>
<%@ include file= "foot.jsp"%>
The code is improvised, has not been tested, just to express the meaning.
===========================================
If you think it's easy, you can expand it. Configure a content page with a profile and taglib to define two tag inserts to add content pages and value to display content directly in the template.
Is it easier to solve the problem that is mentioned earlier? If there is any change in the page, just modify the template page. This will not make a mistake about which page is missing.
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.