One: Description
Struts1.1 later added tiles pack so struts has a choice in the processing of the page. and easier to implement
Reuse of code.
The Division of the page in tiles is a bit like TDK in the Jakarta of another project turbine. Added the concept of layout.
In fact, a page is divided into several pieces. Generally speaking, a page can be divided into the following blocks:
Head Page Header: Store A public information used: logo, if it is the site may be the top piece.
Menu Page Menus: Place a menu to be used in an application, or a connection that is used on every page.
Footer Page Tail: such as copyright information.
The Body page topic content: Each page relatively independent content.
If you press the above division that for each page we just write the contents of the body, others can share reuse.
If most of the pages are basically the same layout, we can even use a JSP file to invoke different body types based on different parameters.
II: Introduction to Tiles Configuration and basic configuration files
Tiles has a configuration file: Tiles-defs.xml
Tiles-defs.xml defines the elements and forms of each page.
Below I will explain a tiles-defs.xml file as shown below
Tiles-defs.xml
-----------------------------------------------
<tiles-definitions>
<!--the constituent name of the definition/layouts/classiclayout.jsp is site.mainlayout-->
<!--will be appended with/layouts/classiclayout.jsp content-->
<definition name= "Site.mainlayout" path= "/layouts/classiclayout.jsp" >
<put name= "title" value= "Tiles Blank Site"/>
<put name= "header" value= "/tiles/common/header.jsp"/>
<put name= "Menu" value= "Site.menu.bar"/>
<!--menu is composed of Site.menu.bar corresponding page-->
<put name= "Footer" value= "/tiles/common/footer.jsp"/>
<put name= "Body" value= "/tiles/body.jsp"/>
</definition>
<!--define Site.index.page, inherit site.mainlayout-->
<definition name= "Site.index.page" extends= "Site.mainlayout" >
<put name= "title" value= "Tiles Blank Site Index"/>
<put name= "Body" value= "/tiles/body.jsp"/>
<!--the above two elements will replace the elements in Site.mainlayout-->
</definition>
Configure the tiles inside the web.xml and configure the Struts action servlet as follows:
Xml
-----------------
<!--Action Servlet Configuration-->
<servlet>
<servlet-name>action</servlet-name>
<!--specify servlet class to use:
-Struts1.0.x:actioncomponentservlet
-Struts1.1:actionservlet
-No Struts:tilesservlet
-->
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<!--Tiles Servlet parameter
Specify configuration file names. There can be several comma
Separated file names
-->
<init-param>
<param-name>definitions-config</param-name>
<param-value>/WEB-INF/tiles-defs.xml</param-value>
</init-param>
<!--Tiles Servlet parameter
Specify Tiles debug level.
O:no Debug Information
1:debug Information
2:more Debug Information
-->
<init-param>
<param-name>definitions-debug</param-name>
<param-value>1</param-value>
</init-param>
<!--Tiles Servlet parameter
Specify Digester debug level. This value is passed to Digester
O:no Debug Information
1:debug Information
2:more Debug Information
-->
<init-param>
<param-name>definitions-parser-details</param-name>
<param-value>0</param-value>
</init-param>
<!--Tiles Servlet parameter
Specify if XML parser should validate the Tiles file.
True:validate. DTD should is specified in file header.
False:no validation
-->
<init-param>
<param-name>definitions-parser-validate</param-name>
<param-value>true</param-value>
</init-param>
Third: Using tiles
If you have configured Tiels-defs.xml, you can then use these definitions in your JSP files.
Use tiles in the same way
3.1:
<tiles:insert definition= "Site.mainlayout" flush= "true"/>
Inserts a page of the site.mainlayout tag
Insert/tutorial/basic/myframesetlayout.jsp
and set the value of title to: my frameset page
Header set to/tutorial/common/header.jsp
Four: PostScript
The use of tiles in his documents is more detailed. These are some simple and basic uses. The specific documentation can be seen
A Tiles-documentation.war bag inside the struts. But even this bag is not very full. Can be passed on the
Connect to the author's homepage to find it.
Personally feel that the use of tiles in doing business use may not be as good as the site to reflect the advantages. But at the beginning of the system
Design to consider and plan the entire UI, which will save a lot of effort when modifying and maintaining, because the usual UI determines
At the end of code writing and completion, all as much as possible using multiple subpages to form a page, behind the beautification and maintenance than directly
It's easy to maintain a large page.
Because I also used a tiles, if the above document has errors, thank you very much for correcting me.
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.