본문 바로가기
개발/개발환경설정

Tiles 설정

by 카리3 2020. 8. 10.

1. POM.xml 설정

<!-- Tiles -->
		 <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-servlet</artifactId>
            <version>${org.apache.tiles-version}</version>
        </dependency>
         <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-api</artifactId>
            <version>${org.apache.tiles-version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-jsp</artifactId>
            <version>${org.apache.tiles-version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-core</artifactId>
            <version>${org.apache.tiles-version}</version>
        </dependency> 
        <dependency>
            <groupId>org.apache.tiles</groupId>
            <artifactId>tiles-template</artifactId>
            <version>${org.apache.tiles-version}</version>
        </dependency>

2. servlet-context.xml 설정

<!-- Tiles -->
    <beans:bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">
        <beans:property name="definitions">
            <beans:list>
                <beans:value>classpath:/spring/tiles/tiles-def.xml</beans:value>
            </beans:list>
        </beans:property>
    </beans:bean>        
    <beans:bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <beans:property name="viewClass" value="org.springframework.web.servlet.view.tiles3.TilesView" />
        <beans:property name="order" value="3" />
    </beans:bean>    
 <!-- Tiles End -->	

3. tiles-def.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>
 
    <!-- (1) 레이아웃을 적용하지않는화면-->    
    <definition name=".login" template="/WEB-INF/views/tilesLayout/loginLayout.jsp">
        <put-attribute name="title" value="" />
        <put-attribute name="header" value="/WEB-INF/views/tilesView/header.jsp" />
        <put-attribute name="menu" value="" />        
        <put-attribute name="footer" value="" />
    </definition>
 
    <!-- (2) 레이아웃을 적용하는화면-->
    <definition name=".root" template="/WEB-INF/views/tilesLayout/baseLayout.jsp">
        <put-attribute name="title" value="" />
        <put-attribute name="header" value="/WEB-INF/views/tilesView/header.jsp" />
        <put-attribute name="menu" value="/WEB-INF/views/tilesView/menu.jsp" />        
        <put-attribute name="footer" value="/WEB-INF/views/tilesView/footer.jsp" />
    </definition>
    
    <!-- (1) -->    
    <definition name="/login/*" extends=".login">
      <put-attribute name="body" value="/WEB-INF/views/login/{1}.jsp" />
    </definition>
 
    <!-- (2) -->
     <definition name="kims:/*" extends=".root">      
      <put-attribute name="body" value="/WEB-INF/views/{1}.jsp" />
    </definition>
   <definition name="kims:/*/*" extends=".root">      
      <put-attribute name="body" value="/WEB-INF/views/{1}/{2}.jsp" />
    </definition>
    <definition name="kims:/*/*/*" extends=".root">      
      <put-attribute name="body" value="/WEB-INF/views/{1}/{2}/{3}.jsp" />
    </definition>
    <definition name="kims:/*/*/*/*" extends=".root">      
      <put-attribute name="body" value="/WEB-INF/views/{1}/{2}/{3}/{4}.jsp" />
    </definition>
</tiles-definitions>

4. jsp 설정

4-1) base-layout.jsp

<%@ page language="java" contentType="text/html; charset=euc-kr"
    pageEncoding="euc-kr"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
 
<html>
<head>
<title>Explosion</title>
<%@ include file="/WEB-INF/include/include-header.jsp" %>
</head>
<body class="wrapper">
    안녕하세요~
    <nav class="navbar navbar-default navbar-static-top" role="navigation" style="margin-bottom: 0">        
        <tiles:insertAttribute name="header"/>        
        <tiles:insertAttribute name="menu" />    
    </nav>
     <div id="page-wrapper">
             <div class="row">
                <div class="col-lg-12">    
                    <h1 class="page-header">${setHeader}</h1>
                </div>
            </div>
            <div class="row">                 
                <tiles:insertAttribute name="body" />                                                  
            </div>
          
     </div>
    
 
    <div class="main_footer">
        <div class="main_footer-inner">
            <tiles:insertAttribute name="footer" />
        </div>
    </div>
</body>
</html>

4-2) header.jsp, body.jsp, footer.jsp 설정

5. Controller 설정

@RequestMapping(value = "/tilesMain.do")
	public String tilesMain(Locale locale, Model model) {
		log.info("tilesMain");

		return "kims:/common/main";
	}

'개발 > 개발환경설정' 카테고리의 다른 글

Spring property 암호화 (jasypt)  (0) 2020.08.11
util:properties 설정  (0) 2020.08.10
Filter 설정  (0) 2020.03.18
Interceptor 설정  (0) 2020.03.17
Aspectj + 어노테이션으로 로그남기기  (0) 2020.03.17