1. Add a jar package. Struts has been integrated {
Function onclick ()
{
Updatecount ('20140901 ')
}
} "Href =" http://www.crystaledu.bj.cn/cmt/cmtsjsqkb.html "target =" _ blank ">
2. Configure the plus-In attribute in Struts-config
3. Configure the taglib attribute in Web. xml and configure the tiles tag.
4. Write tiles profile tiles-def.xml
5. According to the tiles-def.xml write layout, the layout is actually a. jsp, but contains the tiles: insert
6. Write the page
7. Different jump methods:
1) Add a new page (Two JSPs are required for each page, one call page and one page in the Framework)
2) use the paremeter attribute of action.
2. Notes for using the tiles framework:
1. The definitions-config attribute in the plus-In attribute specifies the tiles configuration file. You can specify multiple
2. combination in the tiles configuration file
<definition name="base-definition" path="/layout.jsp"> <put name="sidebar" value="sidebar.jsp"/> <put name="header" value="header.jsp"/> <put name="content" value=""/> <put name="footer" value="footer.jsp"/> </definition> <definition name="index-definition" extends="base-definition"> <put name="content" value="indexContent.jsp"/> </definition> |
In this way, each time you add a new page similar to indexcontent, you only need to configure a new definition inherited from base-definition.
3. The main page and the content page in the layout are different concepts. The main page only needs to have such a few words.
<%@ page contentType="text/html; charset=gb2312" %> <%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" divfix="tiles"%> <tiles:insert definition="index-definition"/> |
The definition attribute specifies the configuration in tiles to be used.
The content page can be written without considering the template.
4. The two different usage methods are not clear yet. However, tiles is really useful.
Iii. Advantages and Disadvantages of tiles:
To be honest, compared with the use of the framework structure, it is still troublesome, and it will increase the number of JSP. However, compared with the frame framework currently used, it is safer. If you directly enter a URL in the address bar of the frame, the frame will no longer exist. This is very dangerous. Tiles makes up for this deficiency.
2)
1. the tiles framework includes the following content: tiles tag library, tiles component configuration file, and tilesplugin plug-in.
2. The <tiles: Insert> label and the JSP include command have the same functions on the JSP page:
<JSP: Include page = "indexcontent. jsp">
<Tiles: insert page = "indexcontent. jsp" Flush = "true"> true indicates that the flush () method of the input stream on the current page is called before the insert operation.
3. Use the tiles tag Library:
1). Class package: struts. jar, commons-digester.jar, commons-beanutils.jar, commons-collections.jar, commons-logging.jar.
2) 2). Add the struts-tiles.tld file. Configure the <tablib> element in the Web file, for example:
<Taglib>
<Taglib-Uri>/WEB-INF/struts-tiles.tld </taglib-Uri>
<Taglib-location>/WEB-INF/struts-tiles.tld </taglib-location>
</Taglib>
3) 3). Configure the ttile component (such as the tiles-defs.xml) in a specialized XML file that is located under the WEB-INF directory.
<Definition name = "common" Path = "/WEB-INF/pages/template. jsp">
<Put name = "menutitle" value = "$ {menutitle}"/>
<Put name = "workflow" value = "$ {workflow}"/>
<Put name = "Header" value = "header. jsp"/>
<Put name = "breadcrumbs" value = "breadcrumbs. jsp"/>
<Put name = "graphics" value = "$ {graphics}"/>
</Definition>
<Definition name = "net. Tiles. Yun" extends = "common">
<Put name = "menutitle" value = "yunchat welcome you here"/>
<Put name = "graphics" value = "Yun graphics"/>
<Put name = "message" value = "tiles. msg.001"/>
<Put name = "workflow" value = "TT Workflow"/>
<Put name = "breadcrumbs" value = "breadcrumbs. jsp"/>
<Put name = "Header" value = "header. jsp"/>
</Definition>
4) 4) configure the tilesplugin plug-in the struts configuration file
<Plug-in classname = "org. Apache. Struts. Tiles. tilesplugin">
<! -Path to XML definition file->
<Set-Property = "definitions-config" value = "/WEB-INF/tiles-defs.xml,/WEB-INF/tiles-defs-yun.xml"/>
<! -Set module-awareness to true->
<Set-Property = "moduleaware" value = "true"/>
<Set-Property = "definition-paser-validate"
Value = "true"/>
</Plug-in>
Definition-paser-validate parameter: Specifies whether the XML Parser verifies the tiles configuration file. The default value is true;
5) 5) Configure actionservlet in the web. xml file
To ensure that the tilesplugin plug-in is loaded when the web application starts, the actionservlet controller should be added. The actionservlet controller can load all the plug-ins during initialization.
6) 6) insert the tiles component into the JSP file and use the tiles component attributes.
4. You can directly call the tiles component in struts action.
<Action-mappings>
<Action Path = "/tiles_action" scope = "requests"
Type = "tilesaction" validate = "true">
<Forward name = "success" Path = "net. Tiles. Yun"
Redirect = "false"/>
</Action>
<Action Path = "/tiles_action2" type = "tilesaction" parameter = "net. Tiles. Yun">
</Action>
</Action-mappings>
5. A combination of tiles components:
<Definition name = "common" Path = "/WEB-INF/pages/template. jsp">
<Put name = "menutitle" value = "tiles-definition" type = "definition"/>
......
</Definition>
<Put> The Value Attribute of the child element specifies the name of the contained tiles component. Set the type attribute to "Definition", indicating that the value attribute specifies the tiles component rather than the JSP file.
6. Extended tiles components:
<Definition name = "common" extends = "base-definition">
The extends attribute specifies the extended parent tiles component.
7. Use of tiles on JSP pages:
(1) Insert to the JSP page:
<Tiles: insert page = "/layouts/commonlayout. jsp" Flush = "true"/>
(2) Insert a tiles and pass the attribute value simultaneously:
<Tiles: insert attribute = "Header">
<Tiles: Put name = "menutitle" beanname = "menutitle"/>
<Tiles: Put name = "graphics" beanname = "graphics"/>
</Tiles: Insert>
<Tiles: insert attribute = "Breadcrumbs">
<Tiles: Put name = "workflow" beanname = "workflow"/>
<Tiles: Put name = "message" beanname = "message"/>
<Tiles: Put name = "graphics" beanname = "graphics"/>
</Tiles: Insert>
(3) Obtain an attribute as a string.
<Tiles: getasstring name = "title">
(4) Insert tiles through reference attributes
<Tiles: insert attribute = "Header">