본문 바로가기
IT/Spring

spring + tiles

by 최고영회 2013. 12. 24.
728x90
반응형
SMALL
servlet-context.xml
a) tiles 설정을 추가
<beans:bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<beans:property name="definitions"> 
<beans:list>
<beans:value>/WEB-INF/tiles-test.xml</beans:value>
</beans:list>
</beans:property>
</beans:bean>
b) tiles-test.xml 관련 설정 확인
c) tilesview 설정을 추가
<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>
d) 기존의 InternalResourceViewResolver의 우선순위를 낮춤
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
<beans:property name="order" value="2" />
</beans:bean>

* 위의 설정은 기존의 viewResolver를 후순위로 낮추고, 1순위로 tilesViewResolver를 추가함

tiles-test.xml 파일 생성
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
<tiles-definitions>

<definition name="base_layout" templateExpression="/WEB-INF/views/template/layout.jsp">
<put-attribute name="header" expression="/WEB-INF/views/template/header.jsp" />
<put-attribute name="footer" expression="/WEB-INF/views/template/footer.jsp" />
<put-attribute name="left"   expression="/WEB-INF/views/template/left.jsp" />
<put-attribute name="body"   expression="/WEB-INF/views/template/body.jsp" />
</definition>

<definition name="content1" extends="base_layout">
<put-attribute name="title" value="컨텐트 화면" />
<put-attribute name="body" expression="/WEB-INF/views/test.jsp" />
</definition>

</tiles-definitions>


* tiles-test 설정
 - header(상단메뉴), footer(하단), left(좌측메뉴), body(내용) 로 이루어진 base_layout 사용
 - definition name은 spring의 Controller에서 return하는 String 값에 매치 

Controller
@RequestMapping 형태의 메소드에서, tiles definition name을 리턴하여 해당 레이아웃이 적용된 jsp 표시


@Controller
@RequestMapping("/content1")
public class TestController {
@RequestMapping(method = RequestMethod.GET)
public String test(HttpServletRequest req) {
return "content1";
}
}



layout jsp 파일
base_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><tiles:getAsString name="title" /></title>
</head>
<body>
<div style="border:solid 10px green;clear:both;width:1000px;height:20px;">
<tiles:insertAttribute name="header" />
</div>
<div style="border:solid 10px yellow;clear:both;float:left;position:relative;width:120px;">
<tiles:insertAttribute name="left" />
</div>
<div style="border:solid 10px black;float:left;position:relative;width:860px;">
<tiles:insertAttribute name="body" />
</div>
<div style="border:solid 10px green;clear:both;width:1000px;">
<tiles:insertAttribute name="footer" />
</div>
</body>
</html>





728x90
반응형
LIST

'IT > Spring' 카테고리의 다른 글

ehcache  (0) 2013.12.24
spring file download  (0) 2013.12.24
Spring2.5 Ajax  (0) 2013.12.24
udp-inbound-channel-adapter 이용 was 에 udp server socket 구성  (0) 2013.12.24
springMVC + iBatis  (0) 2013.12.24