Use of apache tiles page templates, apachetiles

Source: Internet
Author: User

Use of apache tiles page templates, apachetiles

Jar package maven

<! -- Tiles template --> <dependency> <groupId> org. apache. tiles </groupId> <artifactId> tiles-extras </artifactId> <version> 3.0.5 </version> </dependency>

Springmvc-servlet.xml Configuration

<Bean id = "tilesViewResolver" class = "org. springframework. web. servlet. view. urlBasedViewResolver "> <property name =" viewClass "value =" org. springframework. web. servlet. view. tiles3.TilesView "> </property> <property name =" order "value =" 1 "/> </bean> <bean id =" tilesConfigurer "class =" org. springframework. web. servlet. view. tiles3.TilesConfigurer "> <property name =" definitions "> <list> <value> classpath: layout. xml </Value> </list> </property> </bean> <! -- Define the location of the JSP file --> <bean id = "viewResolver" class = "org. springframework. web. servlet. view. internalResourceViewResolver "> <property name =" prefix "value ="/WEB-INF/pages/"/> <property name =" suffix "value = ". jsp "/> <property name =" order "value =" 1 "/> </bean>

Layout. xml

<? Xml version = "1.0" encoding = "UTF-8"?> <! DOCTYPE tiles-definitions PUBLIC "-// Apache Software Foundation // DTD Tiles Configuration 3.0 // EN" "http://tiles.apache.org/dtds/tiles-config_3_0.dtd"> <tiles-definitions> <! -- Project --> <! -- Admin --> <! -- Admin base --> <definition name = "base_admin"> <put-attribute name = "admin_head" value = "/WEB-INF/pages/common/template/admin/adminHead. jsp "> </put-attribute> <put-attribute name =" admin_left "value ="/WEB-INF/pages/common/template/admin/adminLeft. jsp "> </put-attribute> </definition> <! -- Home page user management --> <definition name = "index" template = "/WEB-INF/pages/index. jsp "extends =" base_admin "> <put-attribute name =" flag "type =" string "value =" 1 "> </put-attribute> </definition> </ tiles-definitions>
<Definition name = "base_admin"> the controller corresponding to name returns view


Jsp page usage:
<% @ Page language = "java" contentType = "text/html; charset = UTF-8 "pageEncoding =" UTF-8 "%> <% ---- %> <% @ include file ="/WEB-INF/pages/common/taglibs. jsp "%> <% ---- %> <% @ include file ="/WEB-INF/pages/common/resource. jsp "%> <% ---- %> <! DOCTYPE html> 

<Tiles: insertAttribute name = "admin_head">

 

Summary: I personally think the tiles label is not too convenient. The only thing that is, the template must be a view return, and then various references, and the use of various el expressions, is that the returned view template makes me feel uncomfortable, it is not as flexible as sitemesh. I started to use tiles. Now I want to change it to sitemesh.

Related Article

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.