wasup
Spring) Tiles 사용해보기 본문
반응형
JSP : Template : 동적배치
Spring : Tiles : 동적배치
new project name : tilestest
package nema : co.kr.tilestest
pom.xml
<!-- tiles -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>2.2.2</version>
</dependency>
<!-- tiles-core -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>2.2.2</version>
</dependency>
servlet-content.xml
org.springframework.web.servlet.view.tiles2.TilesConfigurer
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans
xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing
infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving
up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<beans:bean
class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<beans:property name="definitions">
<beans:list>
<beans:value>/WEB-INF/tiles-def.xml</beans:value>
</beans:list>
</beans:property>
</beans:bean>
<beans:bean
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<beans:property name="viewClass"
value="org.springframework.web.servlet.view.tiles2.TilesView" />
<beans:property name="viewNames" value=".*" />
<beans:property name="order" value="1" />
</beans:bean>
<!-- Resolves views selected for rendering by @Controllers to .jsp resources
in the /WEB-INF/views directory -->
<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>
<context:component-scan
base-package="co.kr.tilestest" />
</beans:beans>
/WEB-INF/tiles-def.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.1//EN"
"http://tiles.apache.org/dtds/tiles-config_2_1.dtd">
<tiles-definitions>
<definition name=".main.layout" template="/WEB-INF/views/layout.jsp">
<put-attribute name="header" value="/WEB-INF/views/header.jsp"/>
<put-attribute name="side" value="/WEB-INF/views/side.jsp"/>
<put-attribute name="content" value="/WEB-INF/views/board/list.jsp"/>
<put-attribute name="footer" value="/WEB-INF/views/footer.jsp"/>
</definition>
<definition name=".main.*.*" extends=".main.layout">
<put-attribute name="content" value="/WEB-INF/views/{1}/{2}.jsp"/>
</definition>
</tiles-definitions>
만들 layout 목록
<definition name=".main.layout" template="/WEB-INF/views/layout.jsp">
<put-attribute name="header" value="/WEB-INF/views/header.jsp"/>
<put-attribute name="side" value="/WEB-INF/views/side.jsp"/>
<put-attribute name="content" value="/WEB-INF/views/board/list.jsp"/>
<put-attribute name="footer" value="/WEB-INF/views/footer.jsp"/>
</definition>
header.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>header</title>
</head>
<body>
<h2 align="center"></h2>
<table boarder="0" style="width:100%;min-width:60%">
<tr>
<td align="left">
<a href="/tilestest/" style="text-decoration:none;">
<img srd="resources/logo.png" alt="로고"/>
</a>
</td>
</tr>
</table>
<td align="right">
<a href="/tilestest/board/list.do">게시판</a>
<a href="">q&a</a>
<a href="">faq</a>
<a href="">공지사항</a>
<a href="/tilestest/insertForm.do">회원가입</a>
<a href="/tilestest/loginForm.do">로그인</a>
</td>
</body>
</html>
side.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>side</title>
</head>
<body>
<a href="/tilestest/board/list.do">게시판</a><br/>
<a href="">q&a</a><br/>
<a href="">faq</a><br/>
<a href="">공지사항</a><br/>
<a href="/tilestest/insertForm.do">회원가입</a><br/>
<a href="/tilestest/loginForm.do">로그인</a>
</body>
</html>
footer.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>footer</title>
</head>
<body>
<table boarder="0" style="width:100%;min-width:60%">
<tr>
<td>
본 사이트는 무단으로 복제하는 것을 허용하지 않습니다.
tel : 000-0000-0000
관리자 : 임나연
</td>
</tr>
</table>
<td align="right">
<a href="/tilestest/board/list.do">게시판</a>
<a href="">q&a</a>
<a href="">faq</a>
<a href="">공지사항</a>
<a href="/tilestest/insertForm.do">회원가입</a>
<a href="/tilestest/loginForm.do">로그인</a>
</td>
</body>
</html>
board/list.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>list</title>
</head>
<body>
list<br/>
list<br/>
list<br/>
list<br/>
list<br/>
list<br/>
list<br/>
list<br/>
list<br/>
list<br/>
</body>
</html>
layout.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>layout</title>
</head>
<body>
<table board="1" style="width:100%;min-width:60%;">
<tr>
<td colspan="2" height="60" bgcolor="cyan">
<tiles:insertAttribute name="header"></tiles:insertAttribute>
</td>
</tr>
<tr>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
</tr>
</table>
</body>
</html>
참고링크 :
타일즈?
다른버전
https://qh5944.tistory.com/105
반응형
'IT > Java' 카테고리의 다른 글
Spring) spring boot - spring starter project 해보기! (0) | 2021.08.16 |
---|---|
Spring Legacy MiNi Project - STS / tiles 적용 (0) | 2021.08.15 |
Spring Legacy MiNi Project - STS / board view (0) | 2021.08.11 |
Spring Legacy MiNi Project - STS / board java (0) | 2021.08.10 |
Spring) AOP( Aspect Oriented Programming ) / 관점지향 프로그래밍 (0) | 2021.08.09 |
Comments