본문 바로가기
Develops/Spirng

[SPRING] Tiles Framework 이란? (화면 레이아웃 라이브러리)

by SLOTH91 2024. 7. 14.
반응형

Tiles Framework 이란?

웹 화면을 각 영역으로 나눠서, 템플릿을 구성하기 쉽게 해주는 프레임워크이다.

 

 

 

Tiles Framework 환경 구성하기

1. servlet-context.xml 설정

<beans:bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
    <beans:property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView" />
    <beans:property name="order" value="1" />
</beans:bean>
<beans:bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <beans:property name="definitions">
        <beans:list>
            <beans:value>classpath:tiles-defs.xml</beans:value>
        </beans:list>
    </beans:property>
</beans:bean>

 

2. tiles-defs.xml 생성 및 설정

<tiles-definitions>
    <definition name="default_layout" template="/WEB-INF/views/layout/default_layout.jsp">
        <put-attribute name="header" value="/WEB-INF/views/layout/header.jsp" />
        <put-attribute name="footer" value="/WEB-INF/views/layout/footer.jsp" />
    </definition>
    <definition name="*" extends="default_layout">
        <put-attribute name="body" value="/WEB-INF/views/{1}.jsp" />
    </definition>
    <definition name="*/.*" extends="default_layout">
        <put-attribute name="body" value="/WEB-INF/views/{1}/{2}.jsp" />
    </definition>
</tiles-definitions>

 

3. jsp file 생성 및 설정

  • /views/layout/default_layout.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"    pageEncoding="UTF-8"%>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
    <div id="wrap">
        <div id="headerWrap">
            <tiles:insertAttribute name="header" />
        </div>
        <hr />
        <div id="container">
            <div id="contents">
                <tiles:insertAttribute name="body" />
            </div>
        </div>
        <hr />
        <div id="footerWrap">
            <tiles:insertAttribute name="footer" />
        </div>
    </div>
</body>
</html>
  • /views/layout/header.jsp
    • 화면 개발 시 위 레이아웃에 맞게 공통적으로 들어가게 된다.
  • /views/layout/footer.jsp
    • 화면 개발 시 위 레이아웃에 맞게 공통적으로  들어가게 된다.

 

4. pom.xml 설정

<dependency>
     <groupId>org.apache.tiles</groupId>
     <artifactId>tiles-jsp</artifactId>
     <version>2.2.2</version>
</dependency>

 

반응형