728x90
1. 세션 나누기
2. Contoller
- indexController.java
package com.newlecture.web.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
public class indexController implements Controller {
@Override
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
ModelAndView mv = new ModelAndView("root.index");
mv.addObject("data","Hello Spring MVC~");
return mv;
}
}
3. 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="root.*" template="/WEB-INF/view/inc/layout.jsp"> <!-- 루트에 있는 페이지를 만든다-->
<put-attribute name="title" value="공지사항" />
<put-attribute name="header" value="/WEB-INF/view/inc/header.jsp" />
<put-attribute name="body" value="/WEB-INF/view/{1}.jsp" /> <!-- 루트에 있는페이지는 index.jsp ... -->
<put-attribute name="footer" value="/WEB-INF/view/inc/footer.jsp" />
</definition>
<definition name="notice.*" template="/WEB-INF/view/customer/inc/layout.jsp">
<put-attribute name="title" value="공지사항" />
<put-attribute name="header" value="/WEB-INF/view/inc/header.jsp" />
<put-attribute name="visual" value="/WEB-INF/view/customer/inc/visual.jsp" />
<put-attribute name="aside" value="/WEB-INF/view/customer/inc/aside.jsp" />
<put-attribute name="body" value="/WEB-INF/view/customer/notice/{1}.jsp" />
<put-attribute name="footer" value="/WEB-INF/view/inc/footer.jsp" />
</definition>
</tiles-definitions>
1) 두 개의 페이지가 같은데 body부분만 다르다면 ?
앞페이지에서 두개를 각각 나누어서 작성하는 것보다 와일드 카드 사용하는 것이 더 유용
notice.* 이라면
첫번째 * 는 첫번째 와일드카드 {1}
즉,
이러한 상황이라면 notice.*이므로 notice.list -> {1} = list
notice.detail -> {1} = detail
4.
- 보여줄 페이지 작성.jsp (root)
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<!DOCTYPE html>
<html>
<head>
<title>코딩 전문가를 만들기 위한 온라인 강의 시스템</title>
<meta charset="UTF-8">
<title>공지사항목록</title>
<link href="/css/layout.css" type="text/css" rel="stylesheet" />
<link href="/css/index.css" type="text/css" rel="stylesheet" />
<script>
</script>
</head>
<body>
<!-- header 부분 -->
<tiles:insertAttribute name="header" />
<!-- <body> 부분 -->
<tiles:insertAttribute name="body" />
<!-- <footer> 부분 -->
<tiles:insertAttribute name="footer" />
</body>
</html>
- 보여줄 페이지 작성.jsp (detail, list)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %>
<!DOCTYPE html>
<html>
<head>
<title>코딩</title>
<meta charset="UTF-8">
<title><tiles:getAsString name="title" /></title>
</head>
<body>
<!-- header 부분 -->
<tiles:insertAttribute name="header" />
<!-- --------------------------- <visual> --------------------------------------- -->
<!-- visual 부분 -->
<tiles:insertAttribute name="visual" />
<!-- --------------------------- <body> --------------------------------------- -->
<div id="body">
<div class="content-container clearfix">
<!-- --------------------------- <aside> --------------------------------------- -->
<!-- aside 부분 -->
<tiles:insertAttribute name="aside" />
<!-- --------------------------- <main> --------------------------------------- -->
<tiles:insertAttribute name="body" />
</div>
</div>
<!-- ------------------- <footer> --------------------------------------- -->
<tiles:insertAttribute name="footer" />
</body>
</html>
728x90
'SPRING' 카테고리의 다른 글
[Spring] 오라클(Oracle) 연동 (Eclipse) (0) | 2022.05.11 |
---|---|
[Spring] tiles ViewResolver 설정하기 (0) | 2022.05.11 |
[Spring] tiles 지시서 작성하기1 (Eclipse) (0) | 2022.05.11 |
[Spring] tiles 사용법 (Eclipse) (0) | 2022.05.11 |
[Spring] DataSource 이용 (0) | 2022.05.11 |