๐ป
์คํ๋ง ํ๋ ์์ํฌ - [Spring] ํ์ผ์ฆ(Tiles) ์ค์ ํ๊ธฐ ๋ณธ๋ฌธ
์คํ๋ง ํ๋ ์์ํฌ - [Spring] ํ์ผ์ฆ(Tiles) ์ค์ ํ๊ธฐ
๋ํจ๋ 2020. 8. 4. 10:59ํ์ผ์ฆ(Tiles)๋?
ํ์ผ์ฆ๋ ํ์ผ๋ค์ ๋ถ์ด๋ ๊ฒ๊ณผ ๊ฐ์ด ๊ฐ๊ฐ์ ์์ญ์ ๋ถ์ฌ์ ํ๋์ ์นํ์ด์ง์ ํ๋ฉด์ ๊ตฌ์ฑํ๋ ๋ผ์ด๋ธ๋ฌ๋ฆฌ์ด๋ค.
์น ํ์ด์ง์ ์์ญ์ ํฌ๊ฒ header, content, left, nav, footer๋ก ๋๋์ด์ง๋ฉฐ, ์ฌ๋ฌ ์น ํ์ด์ง์์ ์ด ์์ญ๋ค์ ๊ณตํต์ ์ผ๋ก ์ฌ์ฉํ๊ณ ์ถ๋ค๋ฉด ๊ฐ๊ฐ์ ์์ญ์ ํ์ผ์ฆ ํ๊ทธ๋ก ์ง์ ํ์ฌ ํธ๋ฆฌํ๊ฒ ์ฌ์ฉํ ์ ์๋ค.
pom.xml
tiles2๋ฅผ ์ฐ๊ธฐ ์ํด์ pom.xml์ tiles-core, tiles-servlet, tiles-jsp ๊ฐ์ ธ์ค๊ธฐ
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.java</groupId>
<artifactId>homgPage</artifactId>
<name>06_MavenSpringMVC</name>
<packaging>war</packaging>
<version>1.0.0-BUILD-SNAPSHOT</version>
<properties>
<java-version>1.6</java-version>
<org.springframework-version>3.1.1.RELEASE</org.springframework-version>
<org.aspectj-version>1.6.10</org.aspectj-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
</properties>
<dependencies>
<!-- Spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${org.springframework-version}</version>
<exclusions>
<!-- Exclude Commons Logging in favor of SLF4j -->
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${org.springframework-version}</version>
</dependency>
<!-- AspectJ -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>${org.aspectj-version}</version>
</dependency>
<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${org.slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.15</version>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
<scope>runtime</scope>
</dependency>
<!-- @Inject -->
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<!-- Servlet -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet.jsp</groupId>
<artifactId>jsp-api</artifactId>
<version>2.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- Test -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.7</version>
<scope>test</scope>
</dependency>
<!-- Library ์ถ๊ฐ -->
<!-- JSTL -->
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<!-- STANDARD -->
<!-- https://mvnrepository.com/artifact/taglibs/standard -->
<dependency>
<groupId>taglibs</groupId>
<artifactId>standard</artifactId>
<version>1.1.2</version>
</dependency>
<!-- AOP -->
<!-- https://mvnrepository.com/artifact/aopalliance/aopalliance -->
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver -->
<dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.8.13</version>
</dependency>
<!-- https://mvnrepository.com/artifact/cglib/cglib -->
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
</dependency>
<!-- DB / spring jdbc, mybatis, spring mybatis, oracle(tomcat server) C:\sohyunkim\spring\apache-tomcat-9.0.35\bin -->
<!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jdbc</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
<version>3.4.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.3.2</version>
</dependency>
<!-- Download / -->
<!-- https://mvnrepository.com/artifact/commons-io/commons-io -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>1.3.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-fileupload/commons-fileupload -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.3</version>
</dependency>
<!-- template -->
<!-- https://mvnrepository.com/artifact/org.apache.tiles/tiles-jsp -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-jsp</artifactId>
<version>2.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tiles/tiles-servlet -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-servlet</artifactId>
<version>2.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.tiles/tiles-core -->
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>2.2.2</version>
</dependency>
<!-- POOL -->
<!-- https://mvnrepository.com/artifact/commons-pool/commons-pool -->
<dependency>
<groupId>commons-pool</groupId>
<artifactId>commons-pool</artifactId>
<version>1.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-dbcp/commons-dbcp -->
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>1.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-collections/commons-collections -->
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<additionalProjectnatures>
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature>
</additionalProjectnatures>
<additionalBuildcommands>
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand>
</additionalBuildcommands>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArgument>-Xlint:all</compilerArgument>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.2.1</version>
<configuration>
<mainClass>org.test.int1.Main</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
WEB-INF/template ํด๋ ์์ฑํ ํ footer.jsp, header.jsp, layout.jsp, menu.jsp ํ์ผ์ ์์ฑํด์ค๋ค.
ํ ํ๋ฆฟ์์ ํด๋ ์์ฑ template
content๋ ๋ณด๋ด์ฃผ๋ ๊ฒ์ด๊ธฐ๋๋ฌธ์ ์์ฑ X
layout.jsp๋ก ๊ฐ์ ์์ฑํด์ค๋ค.
servlet-context.xml
๋ทฐ ๋ฆฌ์กธ๋ฒ๋ฅผ ์ค์ ํด์ค๋ค. tiles ๊ด๋ จ ์ค์ ์ ์์ฑํด์ค๋ค.
Maven Dependencies > spring-webmvc-3.1.1.RELEASE.jar ์์ org.springframework.web.servlet.view.tiles2
<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/mvc https://www.springframework.org/schema/mvc/spring-mvc.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven />
<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />
<resources mapping="/css/**" location="/css/" />
<resources mapping="/javascript/**" location="/javascript/" />
<!-- ์ฃผ์์ผ๋ก ๋ซ์์ฃผ๊ธฐ -->
<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<!-- <beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<beans:property name="prefix" value="/WEB-INF/views/" />
<beans:property name="suffix" value=".jsp" />
</beans:bean> -->
<!-- Tiles2 ์ถ๊ฐ -->
<!-- Tiles ์ค์ ํ์ผ -->
<beans:bean id ="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
<beans:property name="definitions">
<beans:list>
<beans:value>/WEB-INF/tiles/tiles.xml</beans:value>
</beans:list>
</beans:property>
</beans:bean>
<!-- Tiles2 ๋ทฐ ๋ฆฌ์กธ๋ฒ -->
<beans:bean id ="tilesViewResolver" class="org.springframework.web.servlet.view.tiles2.TilesViewResolver">
<beans:property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
</beans:bean>
<!-- DI -->
<context:component-scan base-package="com.java..*" />
<!-- AOP -->
<aop:aspectj-autoproxy/>
<!-- FileUpload -->
<beans:bean class="org.springframework.web.multipart.commons.CommonsMultipartResolver" id="multipartResolver">
<beans:property name="maxUploadSize" value="502400"/>
<!-- 102400 -->
<beans:property name="defaultEncoding" value="utf-8"/>
</beans:bean>
</beans:beans>
WEB-INF/tiles ํด๋๋ฅผ ์์ฑํด์ค๋ค.
tiles.xmlํ์ผ์ ์์ฑํ๋ค.
https://tiles.apache.org/framework/tiles-core/dtddoc/tiles-config_3_0.dtd.html
์์ ๋งํฌ์์ ๋ณต์ฌํ Doctype์ ์ฝ์
<!DOCTYPE tiles-definitions PUBLIC "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN" "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
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="layout" template="/WEB-INF/template/layout.jsp">
<put-attribute name="header" value="/WEB-INF/template/header.jsp"/>
<put-attribute name="menu" value="/WEB-INF/template/menu.jsp"/>
<put-attribute name="content" value=""/>
<put-attribute name="foot" value="/WEB-INF/template/footer.jsp"/>
</definition>
<!-- content -->
<definition name="*.tiles" extends="layout">
<put-attribute name="content" value="/WEB-INF/views/{1}.jsp"></put-attribute>
</definition>
<definition name="*/*.tiles" extends="layout">
<put-attribute name="content" value="/WEB-INF/views/{1}/{2}.jsp"></put-attribute>
</definition>
<definition name="*/*/*.tiles" extends="layout">
<put-attribute name="content" value="/WEB-INF/views/{1}/{2}/{3}.jsp"></put-attribute>
</definition>
<!-- tiles ์ ์ธ ์ํจ๋ค -->
<definition name="empty" template="/WEB-INF/template/empty.jsp">
<put-attribute name="content" value=""/>
</definition>
<definition name="*/*.empty" extends="empty">
<put-attribute name="content" value="/WEB-INF/views/{1}/{2}.jsp"/>
</definition>
</tiles-definitions>
์ด๋ ๊ฒ ์ค์ ํ๊ณ ๋ ํ content๋ ๋น์๋๊ณ layout.jsp๋ก ๊ฐ์ ์์ฑํด์ค๋ค.
menu.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<c:set var="root" value="${pageContext.request.contextPath}"/>
<c:set var = "id" value="${id}" scope="session"/>
<a href="${root}/member/test.do">Spring MVC Start!!!</a>
<c:if test="${memberLevel==null}">
<h3>ํ์๊ด๋ฆฌ</h3>
<a href="${root}/member/register.do">ํ์๊ฐ์
</a>
<h3>๋ก๊ทธ์ธ</h3>
<a href="${root}/member/login.do">๋ก๊ทธ์ธ</a>
</c:if>
<c:if test="${memberLevel!=null}">
<a href="${root}/member/delete.do">ํ์ํํด</a>
<a href="${root}/member/update.do">ํ์์์ </a>
<a href="${root}/member/logout.do">๋ก๊ทธ์์</a>
<c:if test="${memberLevel=='MA'}">
<h3>๊ด๋ฆฌ์ ํ์ด์ง</h3>
<a href="">ํ์๊ด๋ฆฌ</a>
</c:if>
</c:if>
<br/><br/>
<h3>ํ์ผ ๊ฒ์ํ</h3>
<a href="${root}/fileBoard/write.do">ํ์ผ๊ฒ์ํ ์ฐ๊ธฐ</a>
<br/><br/>
<a href="${root}/fileBoard/list.do">ํ์ผ ๋ฆฌ์คํธ</a>
</body>
</html>
footer.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3 style="color:red">FOOT</h3>
</body>
</html>
header.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3 style="color:blue">header</h3>
</body>
</html>
layout.jsp
<%@ 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>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<!-- header -->
<tiles:insertAttribute name="header"/>
<hr color="red"/>
<!-- menu -->
<tiles:insertAttribute name="menu"/>
<hr color="pink"/>
<!-- ๊ณ์ ๋ฐ๋๋ ๋ด์ฉ๋ถ -->
<tiles:insertAttribute name="content"/>
<hr color="blue"/>
<!-- foot -->
<tiles:insertAttribute name="foot"/>
</body>
</html>
Controller ํ์ผ๋ก ๊ฐ์ ํ์ฅ์๋ฅผ .tiles ๋ก ๋ฐ๊ฟ์ฃผ์ด์ผ์ง ํ ํ๋ฆฟ์ด ์ ์ฉ๋๋ค. ์ฒ์๋ถํฐ ํ ํ๋ฆฟ์ ๊ฑธ๊ณ ์์ฑํ๋ ๊ฒ์ด ์ข๋ค.
[com.java.homePage] HomeController.java
package com.java.homePage;
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
/**
* Handles requests for the application home page.
*/
@Controller
public class HomeController {
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
/**
* Simply selects the home view to render by returning its name.
*/
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Locale locale, Model model) {
logger.info("Welcome home! The client locale is {}.", locale);
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
model.addAttribute("serverTime", formattedDate );
return "home.tiles";
}
}
[com.java.member.controller] MemberController.java
package com.java.member.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
import org.springframework.web.servlet.view.InternalResourceView;
import com.java.aop.HAspect;
import com.java.member.dto.MemberDto;
import com.java.member.service.MemberService;
@Controller
public class MemberController{ //Command
@Autowired
private MemberService memberService;
@RequestMapping(value="/member/test.do", method=RequestMethod.GET)
public ModelAndView testing(HttpServletRequest request, HttpServletResponse response) {
System.out.println("OK");
//Service - Dao / Dto - Service
//์ต์์ ํด๋์ค๋ View
/*
InternalResourceView view = new InternalResourceView("/WEB-INF/member/test.jsp");
ModelAndView mav = new ModelAndView();
mav.addObject("msg", "hi");
mav.setView(view);
*/
//๋ค์ํ ์์ฑ์๊ฐ ์๊ธฐ์ ๊ทธ์ ๋ง์ถฐ์ ์ฌ์ฉ!!!
//ModelAndView mav = new ModelAndView(view);
ModelAndView mav = new ModelAndView("member/test.tiles");
mav.addObject("msg", "hi");
return mav;
}
@RequestMapping(value="/member/register.do", method=RequestMethod.GET)
public ModelAndView memberRegister(HttpServletRequest request, HttpServletResponse response) {
return new ModelAndView("member/register.tiles");
}
@RequestMapping(value="/member/registerOk.do", method=RequestMethod.POST)
public ModelAndView memberRegisterOk(HttpServletRequest request, HttpServletResponse response, MemberDto memberDto) {
HAspect.logger.info(HAspect.logMsg + memberDto.toString());
ModelAndView mav = new ModelAndView();
mav.addObject("memberDto", memberDto);
memberService.memberRegisterOk(mav);
return mav;
}
@RequestMapping(value="/member/idCheck.do", method=RequestMethod.GET)
public ModelAndView memberidCheck(HttpServletRequest request, HttpServletResponse response) {
ModelAndView mav = new ModelAndView();
mav.addObject("request", request);
memberService.memberidCheck(mav);
return mav;
}
@RequestMapping(value="/member/zipcode.do", method=RequestMethod.GET)
public ModelAndView memberZipcode(HttpServletRequest request, HttpServletResponse response) {
ModelAndView mav = new ModelAndView();
mav.addObject("request", request);
memberService.memberZipcode(mav);
return mav;
}
@RequestMapping(value="/member/login.do", method=RequestMethod.GET)
public ModelAndView memberLogin(HttpServletRequest request, HttpServletResponse response) {
return new ModelAndView("member/login.tiles");
}
@RequestMapping(value="/member/loginOk.do", method=RequestMethod.POST)
public ModelAndView memberLoginOk(HttpServletRequest request, HttpServletResponse response) {
ModelAndView mav = new ModelAndView();
mav.addObject("request", request);
memberService.memberloginOk(mav);
return mav;
}
@RequestMapping(value="/member/main.do", method=RequestMethod.GET)
public ModelAndView main(HttpServletRequest request, HttpServletResponse response) {
ModelAndView mav = new ModelAndView();
mav.addObject("request", request);
memberService.main(mav);
return mav;
}
@RequestMapping(value="/member/logout.do", method=RequestMethod.GET)
public ModelAndView memberLogout(HttpServletRequest request, HttpServletResponse response) {
ModelAndView mav = new ModelAndView();
mav.addObject("request", request);
memberService.memberloginOut(mav);
return mav;
}
@RequestMapping(value="/member/update.do", method=RequestMethod.GET)
public ModelAndView memberUpdate(HttpServletRequest request, HttpServletResponse response) {
//select ์ถ๊ฐ
ModelAndView mav = new ModelAndView();
mav.addObject("request", request);
memberService.memberUpdate(mav);
return mav;
}
@RequestMapping(value="/member/updateOk.do", method=RequestMethod.POST)
public ModelAndView memberUpdateOk(HttpServletRequest request, HttpServletResponse response) {
ModelAndView mav = new ModelAndView();
mav.addObject("request", request);
//memberService.memberUpdate(mav);
return mav;
}
}
[com.java.member.service] MemberServiceImp.java
package com.java.member.service;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.ModelAndView;
import com.java.aop.HAspect;
import com.java.member.dao.MemberDao;
import com.java.member.dto.MemberDto;
import com.java.member.dto.ZipcodeDto;
//๊ตฌํ ํด๋์ค
@Component
public class MemberServiceImp implements MemberService {
@Autowired
private MemberDao memberDao;
@Override
public void memberRegisterOk(ModelAndView mav) {
Map<String, Object> map = mav.getModelMap();
MemberDto memberDto = (MemberDto)map.get("memberDto");
memberDto.setMemberLevel("BA");
int check = memberDao.memberinsert(memberDto);
HAspect.logger.info(HAspect.logMsg + check);
mav.addObject("check", check);
mav.setViewName("member/registerOk.tiles");
}
@Override
public void memberidCheck(ModelAndView mav) {
Map<String, Object> map = mav.getModelMap();
HttpServletRequest request = (HttpServletRequest)map.get("request");
String id = request.getParameter("id");
HAspect.logger.info(HAspect.logMsg + id);
int check = memberDao.memberidCheck(id);
HAspect.logger.info(HAspect.logMsg + check);
mav.addObject("check", check);
mav.addObject("id", id);
mav.setViewName("member/idCheck.empty");
}
@Override
public void memberZipcode(ModelAndView mav) {
Map<String, Object> map = mav.getModelMap();
HttpServletRequest request = (HttpServletRequest) map.get("request");
String dong = request.getParameter("dong");
if(dong!=null) {
List <ZipcodeDto> zipcodeDto = memberDao.zipcode(dong);
HAspect.logger.info(HAspect.logMsg + zipcodeDto.size());
mav.addObject("zipcodeList", zipcodeDto);
}
mav.setViewName("member/zipcode.empty");
}
@Override
public void memberlogin(ModelAndView mav) {
// TODO Auto-generated method stub
}
@Override
public void memberloginOk(ModelAndView mav) {
Map<String, Object> map = mav.getModelMap();
HttpServletRequest request = (HttpServletRequest)map.get("request");
String id = request.getParameter("id");
String password=request.getParameter("password");
int check = memberDao.loginOk(id, password);
HAspect.logger.info(HAspect.logMsg + check);
mav.addObject("id", id);
mav.addObject("password", password);
mav.addObject("memberLevel", "BB");
mav.setViewName("member/loginOk.tiles");
}
@Override
public void main(ModelAndView mav) {
mav.setViewName("member/main.tiles");
}
@Override
public void memberloginOut(ModelAndView mav) {
Map<String, Object> map = mav.getModelMap();
HttpServletRequest request = (HttpServletRequest)map.get("request");
String id = request.getParameter("id");
String password=request.getParameter("password");
int check = memberDao.loginOk(id, password);
HAspect.logger.info(HAspect.logMsg + check);
mav.addObject("id", id);
mav.addObject("password", password);
mav.addObject("memberLevel", "BB");
mav.setViewName("member/logout.tiles");
}
@Override
public void memberUpdate(ModelAndView mav) {
Map<String, Object> map = mav.getModelMap();
HttpServletRequest request = (HttpServletRequest)map.get("request");
String id = request.getParameter("id");
String password=request.getParameter("password");
//int check = memberDao.loginOk(id, password);
HAspect.logger.info(HAspect.logMsg + id + "@@" + password);
mav.addObject("id", id);
mav.setViewName("member/update.tiles");
}
@Override
public void memberUpdateOk(ModelAndView mav) {
Map<String, Object> map = mav.getModelMap();
HttpServletRequest request = (HttpServletRequest)map.get("request");
String id = request.getParameter("id");
String password=request.getParameter("password");
int check = memberDao.loginOk(id, password);
HAspect.logger.info(HAspect.logMsg + check);
mav.addObject("id", id);
mav.addObject("password", password);
mav.addObject("memberLevel", "BB");
mav.setViewName("member/updateOk.tiles");
}
}
idCheck.jsp, zipcode.jsp ์ ๊ฒฝ์ฐ์๋ template์ด ์ ์ฉ๋๋ฉด ์๋๊ธฐ๋๋ฌธ์
tempateํด๋์ empty.jspํ์ผ์ ์์ฑํด์ค๋ค.
empty.jsp
<%@ 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>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<tiles:insertAttribute name="content"/>
</body>
</html>
tiles.xml
์์ .empty ํ์ผ์ ๋ํ ์ค์ ์ ์ถ๊ฐ๋ก ํด์ค๋ค.
<?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="layout" template="/WEB-INF/template/layout.jsp">
<put-attribute name="header" value="/WEB-INF/template/header.jsp"/>
<put-attribute name="menu" value="/WEB-INF/template/menu.jsp"/>
<put-attribute name="content" value=""/>
<put-attribute name="foot" value="/WEB-INF/template/footer.jsp"/>
</definition>
<!-- content -->
<definition name="*.tiles" extends="layout">
<put-attribute name="content" value="/WEB-INF/views/{1}.jsp"></put-attribute>
</definition>
<definition name="*/*.tiles" extends="layout">
<put-attribute name="content" value="/WEB-INF/views/{1}/{2}.jsp"></put-attribute>
</definition>
<definition name="*/*/*.tiles" extends="layout">
<put-attribute name="content" value="/WEB-INF/views/{1}/{2}/{3}.jsp"></put-attribute>
</definition>
<!-- tiles ์ ์ธ ์ํจ๋ค -->
<definition name="empty" template="/WEB-INF/template/empty.jsp">
<put-attribute name="content" value=""/>
</definition>
<definition name="*/*.empty" extends="empty">
<put-attribute name="content" value="/WEB-INF/views/{1}/{2}.jsp"/>
</definition>
</tiles-definitions>