Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- 생성자
- 배열
- 오버로딩
- layout
- Spring
- Java
- Graphic
- mybatis
- OGNL
- 예외처리
- 국제화
- AWT
- 안드로이드
- Eclips
- Menu
- 클래스
- 어노테이션
- 기본
- HTML
- JSP
- 에러페이지
- JavaScript
- paint
- 이클립스
- 메소드
- 메서드
- oracle
- Android
- struts2
- 전화걸기
Archives
- Today
- Total
note
struts2 Tiles 본문
새로운 파일 생성 하면 등록해야 하는곳
struts.xml -> tiles.xml -> tiles-defs.xml or tiles-defs2.xml
struts.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="main" extends="struts-default,tiles-default">
<!-- 글로벌 설정이 위치하는 곳 -->
</package>
<!-- include files -->
<include file="tiles.xml"/>
</struts>
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="main">
<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>
<action name="menu3">
<result type="tiles">menu3</result>
</action>
<action name="teach">
<result type="tiles">teach</result>
</action>
</package>
</struts>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <display-name>TilesExam</display-name> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <!-- title plug in listener --> <context-param> <param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name> <param-value>/WEB-INF/tiles-defs.xml,/WEB-INF/tiles-defs2.xml</param-value> </context-param> <listener> <listener-class> org.apache.struts2.tiles.StrutsTilesListener </listener-class> </listener> <!-- struts2 filter mappings --> <filter> <filter-name>TilesExample</filter-name> <filter-class> org.apache.struts2.dispatcher.FilterDispatcher </filter-class> </filter> <filter-mapping> <filter-name>TilesExample</filter-name> <url-pattern>/*</url-pattern><!-- if another word is here, error! --> </filter-mapping> </web-app>
tiles-defs.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="/template/classicLayout.jsp">
<put-attribute name="title" value="Struts2 Tiles Example"/>
<put-attribute name="menu" value="/template/menu.jsp"/>
<put-attribute name="header" value="/template/header.jsp"/>
<put-attribute name="body" value="/tiles/body.jsp"/>
<put-attribute name="footer" value="/template/footer.jsp"/>
</definition>
<definition name="menu1" extends="index">
<put-attribute name="body" value="/tiles/body-menu1.jsp"/>
</definition>
<definition name="menu2" extends="index">
<put-attribute name="body" value="/tiles/body-menu2.jsp"/>
</definition>
</tiles-definitions>
tiles-defs2.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>
<!--
template이 tiles-defs.xml과 같은면 아래와 같이 extends 속성에 네임을 명시하고
다를 경우 새롭게 지정
-->
<definition name="menu3" extends="index">
<put-attribute name="body" value="/tiles/body-menu3.jsp"/>
</definition>
<definition name="teach" extends="index">
<put-attribute name="body" value="/tiles/body-new.jsp" />
</definition>
</tiles-definitions>
template/classicLayout.jsp
<%@ page contentType="text/html; charset=utf-8"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-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>
template/ footer.jsp
<%@page contentType="text/html; charset=utf-8"%>
<div align="center" style="background:yellow;">
company information
</div>
template/header.jsp
<%@page contentType="text/html; charset=utf-8"%> <h2 align="center">Struts2 Tiles Examples!!!</h2>
template/menu.jsp
<%@page contentType="text/html; charset=utf-8"%>
<ul>
<li><a href="index.action">main</a></li>
<li><a href="menu1.action">menu1</a></li>
<li><a href="menu2.action">menu2</a></li>
<li><a href="menu3.action">menu3</a></li>
<li><a href="teach.action">강의</a></li>
</ul>
<%@page contentType="text/html; charset=utf-8"%> <b>main page body !!!</b>
tiles/body-menu1.jsp
<%@page contentType="text/html; charset=utf-8"%> <br /> <br /> menu 1 body location
tiles/body-menu2.jsp
<%@page contentType="text/html; charset=utf-8"%> <br /> <br /> menu 2 body location
tiles/body-menu3.jsp
<%@page contentType="text/html; charset=utf-8"%> <br /> <br /> 우리가 만든 최초의 body~~~~
tiles/body-new.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<br/>
<br/>
<br/>
<br/>
<div align="center">오늘은 화요일 타일스 연습 중</div>
struts.xml
<package name="main" extends="struts-default,tiles-default">
tiles-default를 명시해야됨
type=tiles
WEB-INF에 있는
tiles-defs.xml,tiles-defs2.xml 정보를 가지고 옴
그럴려면 등록을 해줘야 하는데
web.xml에 등록
<listener>
<listener-class>
org.apache.struts2.tiles.StrutsTilesListener
</listener-class>
</listener>
tiles-defs.xml의 definition name="index"는 tiles.xml 의 index를 말함
classicLayout.jsp
문자열을 붙일때 <tiles:getAsString name="title" />
페이지를 붙일때 <tiles:insertAttribute name="header"/>
여기에 있는 name은 tiles-defs.xml 에 있는 내용을 갖는다
tiles-defs.xml
<definition name="menu1" extends="index">
<put-attribute name="body" value="/tiles/body-menu1.jsp"/>
</definition>
extends index는 위에 index를 상속받는다
하지만 바뀌는 부분의 내용은 body부분만 바뀜
tiles-defs2.xml
<definition name="menu3" extends="index">
<put-attribute name="body" value="/tiles/body-menu3.jsp"/>
</definition>
라고 명시되어 있는데 위에 index가 명시되어 있지 않아도 tiles-defs.xml 의 index를 받아온다
'JSP > Struts2' 카테고리의 다른 글
| struts2 태그 정리 (0) | 2012.03.12 |
|---|---|
| struts2 Preparable / ModelDriven / workflow (0) | 2012.03.06 |
| struts2 / myBatis 게시판 (0) | 2012.02.27 |
| struts2 데이터베이스 연동 (0) | 2012.02.23 |
| struts2 <s:set /> (0) | 2012.02.23 |
tilesExam.war