일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- 문래삼계탕
- 냉동삼겹살
- 초복
- 인삼주
- 미금
- 미금냉삼
- 분당맛집
- 태국맛집
- 미금맛집
- 냉동삼겹살맛집
- 오이삼계탕
- 냉삼맛집
- 구리맛집
- 정자맛집
- 쌀국수맛집
- 냉삼
- 영등포구청역맛집
- 중복
- 팟타이맛집
- 태국현지느낌식당
- 진타이
- 진타이식당
- 일로집
- 영등포삼계탕
- 눈썹문신제거#붉은잔흔#잠실새내눈썹문신제거#붉은잔흔제거#눈썹문신
- 말복
- 삼계탕
- 쌀국수
- 반계탕
- 팟타이
- Today
- Total
부리부리
tiles 본문
Tiles에 대한 자세한 내용은
http://tiles.apache.org/
참조 한다.
■ Tiles를 사용하는 이유.
1. 매 페이지마다 include를 시키게 되면 나중에 그 파일이 변경 됐을 때 문제가 발생한다. 다 뜯어 고쳐야 한다. 그래서 따로 설정문서에다가 include 파일들을 준비해두고 필요시 가져다 쓰라는 것이다. 나중에 페이지 include할 파일 이름이 바뀔 경우 설정문서에서 만 바꿔주면 된다.
2. 레이아웃을 지원해 준다. 레이아웃패턴을 이용해서 Tiles를 사용할 수 있도록 지원해 준다.
■ Tiles의 진행 순서.
Action에서 결과를 전달하는데 Result가 tiles로 가라고 알려준다. 그럼 Interceptor에서 Plugin인 web.xml에 정의 되어있는 listener에게 알려준다. 그럼 listener는 현재 tiles.xml을 받아서 Plugin에게 알려준다. 그럼 그 Plugin은 tiles.xml 에 정의 되어 있는 각각의 정의 문서를 통해서 적절할 페이지로 이동시킨다. 그러기 위해서는 web.xml에서 tiles-definitions으로 정의하고 있는 그 문서를 참조하기 위한 event listener를 반드시 정의해줘야 한다.
■ 필요한 library
Struts2 library의 lib 폴더(struts-2.0.14\lib) 에서 아래 네개 파일을 추가한다.
struts2-tiles-plugin-2.0.14, tiles-api-2.0.4, tiles-core-2.0.4, tiles-jsp-2.0.4
■ web.xml
<!-- title plug in listener 리스너를 정의 해준다.-->
<listener>
<listener-class>
org.apache.struts2.tiles.StrutsTilesListener
</listener-class>
</listener>
■ tiles.xml(정의문서 : web.xml과 같은 위치에 있다)
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE tiles-definitions PUBLIC
"-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
"http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>
<definition name="index" template="/tiles/classicLayout.jsp"> <!-- index를 요구하면 이 페이지로 전달하겠다. -->
<put-attribute name="title" value="Struts2 Tiles Example"/>
<put-attribute name="menu" value="/tiles/menu.jsp"/>
<put-attribute name="header" value="/tiles/header.jsp"/>
<put-attribute name="body" value="/tiles/body.jsp"/>
<put-attribute name="footer" value="/tiles/footer.jsp"/>
</definition>
<definition name="menu1" extends="index">
<put-attribute name="body" value="/tiles/body-menu1.jsp"/> <!-- "/tiles/body.jsp"/ 이 페이지를 /tiles/body-menu1.jsp"/ 페이지로 바꿔라 -->
</definition>
<definition name="menu2" extends="index">
<put-attribute name="body" value="/tiles/body-menu2.jsp"/>
</definition>
</tiles-definitions>
* 즉 include해야할 파일을 설정 문서에다가 설정해두고 각각의 페이지에서는 그 속성의 이름만을 쓴다.
■ classicLayout.jsp
<%@ page contentType="text/html; charset=euc-kr"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles"%> <!-- 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>
<table border=0 cellpadding=0 cellspacing=1 bgcolor="#a0a0a0" width="100%">
<tr height=100 valign="middle" bgcolor="#ffffff">
<td colspan=2><tiles:insertAttribute name="header"/></td> <!-- 페이지를 가져올 때 -->
</tr>
<tr height="670" bgcolor="#ffffff">
<td width="15%" valign="top"><tiles:insertAttribute name="menu"/></td>
<td width="85%" align="center"><tiles:insertAttribute name="body"/></td>
</tr>
<tr bgcolor="#ffffff">
<td colspan=2><tiles:insertAttribute name="footer"/></td>
</tr>
</table>
</body>
</html>
* title, header, menu, body 등의 속성은 tiles.xml(정의문서)에 꼭 정의가 되어있어야 한다.
■ tiles.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="tiles" namespace="/tiles" extends="struts-default,tiles-default"> <!-- tiles-default이게 정의 되어 있어야 type에서 tiles를 인식한다 -->
<action name="index">
<result type="tiles">index</result>
</action>
<action name="menu1">
<result type="tiles">menu1</result>
</action>
<action name="menu2">
<result type="tiles">menu2</result>
</action>
</package>
</struts>
* Client가 index을 요구하면 tiles.xml(정의문서)에서 정의하고 있는 index라고 정의 되어있는 속성 이름을 전달하겠다고 알려준다.
'jsp' 카테고리의 다른 글
JSP 페이지 이동 5가지 방법 및 특성 (0) | 2019.02.20 |
---|---|
20190213 jsp(저장경로) (0) | 2019.02.18 |
20190218 JSP (0) | 2019.02.18 |
WEB APPLICATION 구조 (0) | 2019.02.11 |
JSP다운 (0) | 2019.02.11 |