Struts: The first intimate contact with the tiles framework

Source: Internet
Author: User
Tags config

First, how to use the tiles framework

1. Add jar package, struts has been integrated

2. Configure the plus-in properties in Struts-config

3. Configure the Taglib attribute in the Web.xml to match the tiles tag

4. Write Tiles configuration file Tiles-def.xml

5. According to Tiles-def.xml write layout, layout is actually a. JSP, but it contains Tiles:insert

6. Write page

7. Different ways to jump:

1 Add New page (each page needs to write two JSP, a call page, a frame in the page)

2 The Paremeter attribute with the action.

Second, the use of the tiles framework should be noted where:

The Definitions-config property in the 1.plus-in property specifies the tiles configuration file and can specify multiple

Composition relationships in 2.Tiles configuration files

<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>

This way, each time you add a new page like indexcontent, you just need to configure a new inherited from base-definition definition to be OK

3. The content pages in the keynote page and layout are different concepts. The keynote page only needs to have so many words on OK

<%@ page contentType="text/html; charset=gb2312" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" divfix="tiles"%>
<tiles:insert definition="index-definition"/>

Where the definition attribute specifies which configuration in the tiles to use

The content page can be completely regardless of the template problem, directly how to write, how to write.

4. Two different ways of using it are still not clear. But tiles is really good.

Third, the advantages and disadvantages of tiles:

To be honest, it's more cumbersome than using a frame structure, and it increases the number of JSPs. However, compared with the frame frame now used, it is relatively safe. The frame frame now used if you enter a URL directly in the address bar will cause the framework to cease to exist. This is very dangerous. and tiles just to make up for this problem.

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.