In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "what are the characteristics of the Tiles framework", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "what are the characteristics of the Tiles framework" this article.
Tiles framework features and content
The Tiles framework provides a template mechanism for creating Web pages, which separates the layout and content of the page. It allows you to create a template and then dynamically insert content into the template at run time. The Tiles framework is based on JSP's include instruction, but it provides more powerful functions than JSP's include instruction. The Tiles framework has the following features:
◆ creates reusable templates
◆ dynamically builds and loads pages
◆ defines reusable Tiles components
◆ supports internationalization
The Tiles framework contains the following:
◆ Tiles tag Library
Configuration files for ◆ Tiles components
◆ TilesPlugIn plug-in
When developing a Web site, it is often required that all Web pages on the same site have a consistent appearance, such as the same layout, header, footer, and menu.
Using basic JSP statements to create composite web pages
The most basic way to create dynamic Web pages is to create separate JSP files for each page. If the requirements change in the same part of the page, all JSP files must be modified manually. It can be seen that using basic JSP statements to write the above web pages will lead to a lot of redundancy of JSP code and increase the cost of development and maintenance.
Using the include instruction of JSP to create compound web pages
To reduce code redundancy, you can put the same parts of index.jsp and product.jsp in separate JSP files, and then include other JSP files in the index.jsp and product.jsp files through the JSP include directive. This improves the reusability of the code. However, JSP include instructions can not completely avoid code redundancy. Although this scheme reduces duplicate code, the number of JSP files increases, from the original 2 files to 7 files, so the complexity of the software also increases.
Using Tiles:Insert tags to create composite web pages
The tiles:insert tag of the Tiles tag library has the same function as the JSP include directive, and other JSP pages can also be inserted into the current page. Using the tiles:insert tag instead of the JSP include directive to create a composite page has only a slight difference in code, and the advantages and disadvantages are similar. The simple use of tiles:insert tags to create composite pages does not take full advantage of the Tiles framework.
The following two statements have the same effect:
< ?xml:namespace prefix = jsp /> < jsp:include page="indexContent.jsp"> < /jsp:include> < ?xml:namespace prefix = tiles /> < tiles:insert page="indexContent.jsp"> < /tiles:insert>Using Tiles template to create compound web pages
Despite the use of tiles:insert tags, there is still a lot of duplicate code in index.jsp and product.jsp files. In order to improve the reusability and maintainability of Web pages, the template mechanism of Tiles can be introduced. Generally speaking, a Tiles template is a JSP page that describes the layout of a page. The Tiles template only defines the style of the Web page, not the content. Specific content is inserted into the template page only when the Web application is running. The same template can be shared by multiple Web pages. Using templates, you can easily implement all pages of Web applications to maintain the same appearance and layout, without having to hard-code each page. In an application, most pages use the same template, and some pages may need a different appearance, using other templates, so an application may have more than one template.
< %@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles"%> < tiles:insert attribute="sidebar"> < /tiles:insert> < tiles:insert attribute="header"> < /tiles:insert> < tiles:insert attribute="content"> < /tiles:insert> < tiles:insert attribute="footer"> < /tiles:insert> < %@ page contentType="text/html; charset=UTF-8" %> < %@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %> < tiles:insert page="layout.jsp" flush="true"> < tiles:put value="sidebar.jsp" name="sidebar"> < /tiles:put> < tiles:put value="header.jsp" name="header" > < /tiles:put> < tiles:put value="indexContent.jsp" name="content"> < /tiles:put> < tiles:put value="footer.jsp" name="footer" > < /tiles:put> < /tiles:insert>The use of Tiles template mechanism greatly improves the reusability and maintainability of the code, and the template contains the common layout of the web page. If the layout changes, you only need to modify the template file, not the specific web page file. However, as you can see from routines 16-13 and 16-14, although the length of both index.jsp and product.jsp files has been shortened, there is still duplicate code in both.
Basic usage of Tiles components
In order to improve the reusability and flexibility of code, the Tiles framework introduces the concept of Tiles components. The Tiles component can represent a complete web page or part of a web page. Simple Tiles components can be combined into complex Tiles components, or extended into complex Tiles components.
The Tiles framework allows you to configure Tiles components in a special XML file. For example, the following code defines a Tiles component named "index-definition" that describes the entire index.jsp page:
< TILES-DEFINITIONS> < DEFINITION name="index-definition" path="/layout.jsp"> < put value="sidebar.jsp" name="sidebar"> < /put> < put value="header.jsp" name="header"> < /put> < put value="indexContent.jsp" name="content"> < /put> < put value="footer.jsp" name="footer" > < /put> < /DEFINITION> < /TILES-DEFINITIONS>The name attribute of the definition element specifies the name of the Tiles component, the path attribute specifies the template used by the Tiles component, and the put child element of the definition element is used to insert specific web content into the template.
Routines 16-15 tiles-defs.xml
< ?xml version="1.0" encoding="ISO-8859-1" ?>Http://jakarta.apache.org/struts/dtds/tiles-config_1_1.dtd">
< TILES-DEFINITIONS> < DEFINITION name="index-definition" path="/layout.jsp"> < /put> < /put> < /put> < /put> < /DEFINITION> < DEFINITION name="product-definition" path="/layout.jsp"> < put value="sidebar.jsp" name="sidebar"> < /put> < put value="header.jsp" name="header" > < /put> < put value="productContent.jsp" name="content"> < /put> < put value="footer.jsp" name="footer" > < /put> < /DEFINITION> < /TILES-DEFINITIONS>The above code defines two Tiles components that represent the complete index.jsp and product.jsp pages, respectively.
(4) configure the TilesPlugin plug-in in the Strut configuration file as follows:
< PLUG-IN className="org.apache.struts.tiles.TilesPlugin"> < SET-PROPERTY value="/WEB-INF/tiles-defs.xml" property="definitions-config" /> < SET-PROPERTY value="true" property="definitions-parser-validate" /> < /PLUG-IN>The TilesPlugin plug-in is used to load the configuration file for the Tiles component. Several set-property child elements are included in the plug-in element to pass in additional parameters to the TilesPlugin plug-in:
◆ definitions-config parameter: specifies the configuration file for the Tiles component, and if there are multiple profiles, they are separated by commas.
◆ definitions-parser-validate parameter: specifies whether the XML parser validates the Tiles configuration file. Optional values include true and false. The default value is true.
(5) configure ActionServlet in web.xml file
In order to ensure that the TilesPlugin plug-in is loaded when the Web application starts, the ActionServlet controller should be added, and the ActionServlet controller can load all the plug-ins at initialization. The following is the code to configure ActionServlet in the web.xml file:
< SERVLET> < SERVLET-NAME>Action
< /SERVLET-NAME> < SERVLET-CLASS>Org.apache.struts.action.ActionServlet
< /SERVLET-CLASS> < INIT-PARAM> < PARAM-NAME>Config
< /PARAM-NAME> < PARAM-VALUE>/ WEB-INF/struts-config.xml
< /PARAM-VALUE> < /INIT-PARAM> < LOAD-ON-STARTUP>three
< /LOAD-ON-STARTUP> < /SERVLET> < SERVLET-MAPPING> < SERVLET-NAME>Action
< /SERVLET-NAME> < URL-PATTERN>* .do
< /URL-PATTERN> < /SERVLET-MAPPING>(6) insert Tiles components into index.jsp and product.jsp, see routines 16-16 and 16-17:
Routines 16-16 index.jsp
< %@ page contentType="text/html; charset=UTF-8" %> < %@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %> < tiles:insert definition="index-definition"> < /tiles:insert>Routines 16-17 product.jsp
< CCID_NOBR> < CCID_CODE> < %@ page contentType="text/html; charset=UTF-8" %> < %@ taglib uri="/WEB-INF/struts-tiles.tld" prefix="tiles" %> < tiles:insert definition="product-definition"> < /tiles:insert>Call the Tiles component through Struts Action
If the Tiles component represents a complete web page, you can call the Tiles component directly through Struts Action. For example, if you want to invoke the Tiles component named "index-definition" defined in section 16.5.1 through Struts Action, you can configure the following Action mapping in the Struts configuration file:
< ACTION-MAPPINGS> < ACTION path="/index" P type="org.apache.struts.actions.ForwardAction"parameter="index-definition"> < /ACTION> < /ACTION-MAPPINGS>Next, the http://localhost:8080/tilestaglibs/index.do is accessed through the browser, and the request is forwarded to ForwardAction, and then ForwardAction forwards the request to the Tiles component named "index-definition". Finally, on the browser side, the user will see the same page as index.jsp.
By calling Tiles components through Struts Action, we can give full play to the function of Struts framework responsible for process control. In addition, you can reduce the number of JSP files. For example, if you call a Tiles component named "index-definition" directly through Struts Action, you no longer have to create an index.jsp file.
Analyze the combination and extension of Tiles components
The Tiles component is a reusable component. Simple Tiles components can be assembled into complex Tiles components like building blocks. For example, the left part of a Tiles component called "index-definition" can be split into separate Tiles components called "sidebar-definition".
< DEFINITION name="index-definition" path="/layout.jsp"> < put value="sidebar-definition" name="sidebar" type="definition"> < /put>……
< /DEFINITION>The value attribute of the above put child element specifies the name of the included Tiles component, and the type attribute is set to "definition", indicating that the value attribute specifies the Tiles component, not the JSP file.
< DEFINITION name="index-definition" extends="base-definition">These are all the contents of this article entitled "what are the characteristics of the Tiles Framework?" Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.