본문 바로가기

framework/library

Tiles <layout framework>

반응형

#Tiles 


웹프로젝트의 view단의 레이아웃을 잡아주는 프레임워크

라이브러리 다운로드

tiles-2.2.2-bin.zip

tiles-3.0.1-bin.zip



#사용된 jar파일


#web.xml 설정

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.0"

         xmlns="http://java.sun.com/xml/ns/javaee"

                 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

                xsi:schemaLocation="http://java.sun.com/xml/ns/javaee                     

                                               http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">

 

<!--******************************************************

        Tiles setting

               1.Listener 사용

               2.Servlet 사용

*******************************************************-->

        <servlet>

               <servlet-name>tiles</servlet-name>

                      

                       <!-- 사용할 Servlet 클래스 -->

                       <servlet-class>

                              org.apache.tiles.web.startup.TilesServlet

                       </servlet-class>

                       <!-- 위에서 명시된 클래스의 definitions-config변수의 값을 /WEB-INF/tiles.xml 설정 -->

                       <init-param>

                              <param-name>

                                  definitions-config

                              </param-name>

                              <param-value>

                                  /WEB-INF/tiles.xml

                              </param-value>

                       </init-param>

                       <load-on-startup>2</load-on-startup>

        </servlet>

       

<!--******************************************************

        Tiles mapping

*******************************************************-->

        <servlet>

               <servlet-name>tiles-dispatch</servlet-name>

               <servlet-class>org.apache.tiles.web.util.TilesDispatchServlet</servlet-class>

        </servlet>

       

        <servlet-mapping>

               <servlet-name>tiles-dispatch</servlet-name>

               <url-pattern>*.tiles</url-pattern>

        </servlet-mapping>

 

 

</web-app>


#tiles.xml 설정

<?xml version="1.0" encoding="UTF-8"?>

<!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="index" template="/layout.jsp">

               <put-attribute name="header" value="/logo.jsp" />

               <put-attribute name="body" value="/index_body.jsp" />

        </definition>

 

        <definition name="first" template="/layout.jsp" extends="index">

               <put-attribute name="body" value="/first_body.jsp" />

        </definition>

</tiles-definitions>


#JSP 템플릿파일 layout.jsp 생성

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles" %>

<!DOCTYPE html>

<html>

<head>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <title>Insert title here</title>

</head>

<body>

        <header>

               <tiles:insertAttribute name="header" />

        </header>

       

        <article>

               <tiles:insertAttribute name="body" />

        </article>

</body>

</html>


#사용될 JSP파일

-logo.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <title>Insert title here</title>

</head>

<body>

        logo.jsp

</body>

</html>


-index_body.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <title>Insert title here</title>

</head>

<body>

        index_body.jsp

</body>

 

</html>


-first_body.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE html>

<html>

<head>

        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <title>Insert title here</title>

</head>

<body>

first_body.jsp

</body>

</html>


출처-http://javaclass1.tistory.com/118

반응형

'framework/library' 카테고리의 다른 글

Java library  (0) 2013.05.24