View
Sitemesh는 tiles와 유사한 기능을 가진 프레임워크이다. Sitemesh를 이용하면 웹페이지의 공통된 레이아웃을 효율적으로 관리할 수 있다.
1. jar파일 설치
google에서 Sitemesh maven을 치면 download를 할 수 있는 사이트가 나온다.
Maven Repository: opensymphony » sitemesh » 2.4.2
SiteMesh is a web-page layout and decoration framework and web- application integration framework to aid in creating large sites consisting of many pages for which a consistent look/feel, navigation and layout scheme is required. opensymphony sitemesh 2.4.
mvnrepository.com
나는 2.4.2 버전을 다운 받았다.
2.
설치된 jar 파일을 사용하기 위해서 Dynamic Project -> WebContent -> WEB-INF -> lib 폴더에 추가한다.
jar파일을 추가했으면 이제 사이트메쉬를 쓰기위한 환경설정을 해야한다.
환경설정은 web.xml , sitemesh.xml , decorators.xml에서 이루어지므로
WEB-INF에 sitemesh.xml , decorators.xml 파일을 추가한다.
3. web.xml
<filter>
<filter-name>sitemesh</filter-name>
<filter-class>
com.opensymphony.sitemesh.webapp.SiteMeshFilter
</filter-class>
</filter>
<filter-mapping>
<filter-name>sitemesh</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Sitemesh를 이용하기위해 web.xml에 기본적으로 이 코드를 추가해둔다.
4. sitemesh.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
<?xml version="1.0" encoding="UTF-8"?>
<sitemesh>
<property name="decorators-file" value="/WEB-INF/decorators.xml" />
<excludes file="${decorators-file}" />
<page-parsers>
<parser content-type="text/html"
class="com.opensymphony.module.sitemesh.parser.HTMLPageParser" />
</page-parsers>
<decorator-mappers>
<mapper
class="com.opensymphony.module.sitemesh.mapper.ConfigDecoratorMapper">
<param name="config" value="${decorators-file}" />
</mapper>
</decorator-mappers>
</sitemesh>
|
cs |
5. decorators.xml
1
2
3
4
5
6
7
8
9
10
11
|
<?xml version="1.0" encoding="UTF-8"?>
<decorators defaultdir="/WEB-INF/test/decorators">
<decorator name="main" page="decorator.jsp">
<pattern>/*.do</pattern>
</decorator>
<excludes>
<pattern>/**/login*.do</pattern>
</excludes>
</decorators>
|
cs |
- 2번째 줄 : decorators defaultdir 에서 decorator.jsp가 들어있는 폴더의 경로를 지정해준다
- 3번째 줄 : page 에서 decorator.jsp 를 지정해준다
- 4번째 줄 : * 기호를 써서 .do가 들어가는 웹페이지를 열면 공통된 레이아웃이 적용되게 해준다.
- 8번째 줄 : 만약 이 레이아웃이 쓰이는걸 원하지 않는 페이지의 경우 excludes에 적용해둔다.
참고로 decorator들을 관리하기 위해서 /WEB-INF/test/decorators폴더안에 decorator.jsp,headerDeco.jsp,footerDeco.jsp를 지정해두었다.
'Server' 카테고리의 다른 글
AD :: Active directory 사용자 이름 CN값 변경하기 (renaming a user, change cn property of (0) | 2022.03.06 |
---|---|
Network : HTTP Request Message (HTTP 요청 메세지) (0) | 2020.05.12 |
Network : HTTP 란 ? ( Overview of HTTP) (0) | 2020.05.07 |
Spring : 스프링 프레임웍에 Spring Security 적용하기 -1 (0) | 2020.02.08 |
JSP : URI/ ContextPath/ URL/ServletPath의 차이점 (0) | 2019.12.31 |