1. web.xml
2. spring설정파일 : dispatcher-servlet.xm
* api와 tiles-defs.xml 추가
package spring.mvc.tiles.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class TilesController {
@RequestMapping("/mainPage.do")
public String mainPage(){
return "main";//tiles definition name을 viewName으로 return
}
@RequestMapping("/registerForm.do")
public String registerForm(){
return "jsp/register_form";
}
@RequestMapping("/register.do")
public String register(){
return "jsp/register_success";
}
@RequestMapping("/myjsp.do")
public String myjsp(){
return "jsp/myjsp";
}
}
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
메인페이지 입니다.
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
myjsp.jsp입니다.
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<form method="post" action="register.do">
ID : <input type="text" name="id"><br>
이름 : <input type="text" name="name"><br>
나이 : <input type="text" name="age"><br>
<input type="submit" value="전송"/>
</form>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
등록된 정보<p>
ID : ${param.id}<br>
이름 : ${param.name}<br>
나이 : ${param.age}
<!-- 딱 붙일 내용만 보여야 한다. -->
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!-- 인클루드 되므로 보여질 부분만 넣는다. -->
<font size="2">
전화번호 : 111-2222 주소 : 서울시 , 대표 : 홍길동
</font>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!-- 인클루드 되므로 보여질 부분만 넣는다. -->
<h2>우리 주식회사...${requestScope.msg }</h2>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<a href="mainPage.do">메인페이지</a><br>
<a href="registerForm.do">회원가입</a><br>
<a href="myjsp.do">myjsp호출 - no tiles</a><br>
<a href="yourjsp.do">yourjsp호출 - no tiles</a>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="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>
<style type="text/css">
#container{
width:822px;
border: 1px solid black;
}
#header{
padding: 5px;
border-bottom: 1px solid black;
}
#left{
padding: 5px;
height:500px;width:200px;
float:left;
}
#content{
padding: 5px;
border-left: 1px solid black;
height:500px;width:600px;
float:left;
}
#footer{
padding-top:5px;
border-top: 1px solid black;
clear:both; <%--float를 업애줌. 기존에 되어 있는 것을 초기화 --%>
text-align:center;
height:50px;
}
</style>
</head>
<body>
<div id="container" >
<div id="header">
<tiles:insertAttribute name="header"/>
</div>
<div id="left" >
<tiles:insertAttribute name="left"/>
</div>
<div id="content" >
<tiles:insertAttribute name="content"/>
</div>
<div id="footer" >
<tiles:insertAttribute name="footer"/>
</div>
</div>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<!--
타일즈 연동
1. TilesConfigurer를 Bean으로 등록 -> property로 타일즈 설정파일의 위치 지정
2. TilesView를 등록 -> UrlBasedViewResolver를 통해 등록
-->
<bean name="tileConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<property name="definitions">
<list>
<value>/WEB-INF/tiles-defs.xml</value>
</list>
</property>
</bean>
<bean name="tilesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
<property name="order" value="1"/>
</bean>
<bean name="beanNameVR" class="org.springframework.web.servlet.view.BeanNameViewResolver">
<property name="order" value="0"/><!-- 우선 순위를 우선시 한다. -->
</bean>
<!-- Controller등록 -->
<bean name="ctr" class="spring.mvc.tiles.controller.TilesController"/>
<!-- View Class를 Bean으로 등록 -->
<bean name="jsp/myjsp" class="org.springframework.web.servlet.view.InternalResourceView">
<property name="url" value="/jsp/myjsp.jsp"/><!-- View Class를 Bean으로 등록해 두고 우선순위를 0으로 잡아 두어서 jsp/myjsp가 넘어오면 타일즈를 타지 않고 url로 forward 해준다. -->
</bean>
</beans>
<?xml version="1.0" encoding="UTF-8" ?><!-- ISO-8859-1로 되어 있을 경우 한글이 저장이 안됨 따라서 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">
<!-- Definitions for Tiles documentation -->
<tiles-definitions>
<definition name="layout_tiles" template="/template/template.jsp">
<put-attribute name="header" value="/template/header.jsp"/>
<put-attribute name="left" value="/template/left.jsp"/>
<put-attribute name="footer" value="/template/footer.jsp"/>
</definition>
<definition name="main" extends="layout_tiles">
<put-attribute name="content" value="/jsp/main.jsp"/>
<put-attribute name="title" value="메인페이지"/>
</definition>
<definition name="registerForm" extends="layout_tiles">
<put-attribute name="content" value="/jsp/register_form.jsp"/>
<put-attribute name="title" value="등록페이지"/>
</definition>
<definition name="registerSuccess" extends="layout_tiles">
<put-attribute name="content" value="/jsp/register_success.jsp"/>
<put-attribute name="title" value="등록성공페이지"/>
</definition>
</tiles-definitions>
<?xml version="1.0" encoding="UTF-8" ?><!-- ISO-8859-1로 되어 있을 경우 한글이 저장이 안됨 따라서 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">
<!-- Definitions for Tiles documentation -->
<tiles-definitions>
<definition name="layout_tiles" template="/template/template.jsp">
<put-attribute name="header" value="/template/header.jsp"/>
<put-attribute name="left" value="/template/left.jsp"/>
<put-attribute name="footer" value="/template/footer.jsp"/>
</definition>
<definition name="*" extends="layout_tiles">
<put-attribute name="content" value="/jsp/{1}.jsp"/>
<put-attribute name="title" value="메인페이지"/>
</definition>
<definition name="*/*" extends="layout_tiles"><!-- *의 개수는 2개까지 가능하다. -->
<put-attribute name="content" value="/{1}/{2}.jsp"/>
<put-attribute name="title" value="{2}"/>
</definition>
</tiles-definitions>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<!-- DispatcherServlet 등록(front controller) -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<!-- 한글 encoding 처리 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>
org.springframework.web.filter.CharacterEncodingFilter
</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<jsp:forward page="mainPage.do"/>
* 결과
'프로그래밍 > Tiles' 카테고리의 다른 글
Tiles설정파일 작성 및 구현 (0) | 2012.07.06 |
---|---|
Tiles 구성 (0) | 2012.07.06 |
Tiles다운로드 및 설치하기 (0) | 2012.07.06 |
Tiles개요 (0) | 2012.07.06 |