티스토리 뷰
스프링 타일즈 설정하기
※ 이 포스트는 전자정부프레임워크(eGoverment Framework) 3.7 환경에서 Tiles 3 설치과정으로 설명했다.
1. 의존 라이브러리 설치
우선 pom.xml 파일에 dependency 정보를 추가해서 다운로드 받는다.
<!-- pom.xml -->
<dependencies>
<!-- Tiles -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-extras</artifactId>
<version>3.0.8</version>
</dependency>
</dependencies>
2. 환경 설정
그 다음은 타일즈 뷰리졸버(ViewResolver)와 타일즈를 컨트롤할 xml파일 설정을 해준다.
필자는 전자정부(egoverment)에서 작업하여서 dispatcher-servlet.xml에 아래와 같이 설정해줬다.
tiles설정 xml파일의 위치나 이름은 여러분 각자가 편하게 설정하면 된다.
<!-- servlet-context.xml or dispatcher-servlet.xml -->
<bean id="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver"
p:order="1" p:viewClass="org.springframework.web.servlet.view.tiles3.TilesView" />
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles3.TilesConfigurer" >
<property name="definitions">
<value>classpath*:egovframework/spring/context-tiles.xml</value>
</property>
</bean>3. 타일즈(Tiles) 설정
다음은 tiles 설정 xml의 예시다.
타일즈 xml 스키마(schema) 선언이 중요하다.
<!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>
<definition name="sample_layout" templateExpression="/WEB-INF/views/sample/layouts/layout.jsp">
<put-attribute name="header" expression="/WEB-INF/views/sample/layouts/header.jsp" />
<put-attribute name="body" expression="/WEB-INF/views/sample/layouts/body.jsp" />
<put-attribute name="footer" expression="/WEB-INF/views/sample/layouts/footer.jsp" />
</definition>
<definition name="*.sample" extends="sample_layout">
<put-attribute name="body" expression="/WEB-INF/views/sample/{1}.jsp" />
</definition>
<definition name="*/*.sample" extends="sample_layout">
<put-attribute name="body" expression="/WEB-INF/views/sample/{1}/{2}.jsp" />
</definition>
<definition name="*/*/*.sample" extends="sample_layout">
<put-attribute name="body" expression="/WEB-INF/views/sample/{1}/{2}/{3}.jsp" />
</definition>
</tiles-definitions>4. 뷰페이지
필자는 위와같이 파일들을 생성 한 후 아래와 같이 레이아웃 파일을 작성했다.
타일즈 관련 tag를 사용해야 하므로 상단에 taglib를 통해 타일즈 tag를 선언해줘야 한다.
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> <%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="t"%> <!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> <t:insertAttribute name="header" /> </head> <body> <t:insertAttribute name="body" /> <t:insertAttribute name="footer" /> </body> </html>
5. 컨트롤러에서 타일즈를 이용한 뷰 연결
import javax.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping(value = "/sample")
public class MgmtMain {
@RequestMapping(value = "/main.do")
public String main(HttpServletRequest request) {
return "main/index.sample";
}
}
'Programming Framework > Spring' 카테고리의 다른 글
| [Spring] Security CSRF multipart/form-data (0) | 2019.07.21 |
|---|---|
| [Spring] 스프링 시큐리티 로그아웃 설정(Security Logout) (0) | 2019.01.23 |
| [eGovFrame : Eclipse] 전자정부 프레임워크 개발환경 설치 (8) | 2019.01.13 |
| 스프링(Spring)에서 Ajax 요청 / 응답 (0) | 2019.01.07 |
| [Spring]스프링 인터셉터 설정 (0) | 2018.12.28 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- jQuery
- high1
- 스프링
- 이클립스
- 자바
- 하이원
- Entity Framework Core
- Flutter
- asp.net core
- eGovFrame
- ubuntu
- .NET Core
- express
- MySQL
- 전자정부
- CentOS
- Linux
- MariaDB
- DART
- egoverment
- dotnet core
- Fedora
- Spring
- Windows
- JSP
- egov
- php
- Java
- Eclipse
- c#
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 1 | 2 | 3 | 4 | |||
| 5 | 6 | 7 | 8 | 9 | 10 | 11 |
| 12 | 13 | 14 | 15 | 16 | 17 | 18 |
| 19 | 20 | 21 | 22 | 23 | 24 | 25 |
| 26 | 27 | 28 | 29 | 30 | 31 |
글 보관함