<?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"
	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">
	<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->
	<!-- 이 서블릿의 요청 처리 인프라를 정의한다. -->
	
	<!-- Enables the Spring MVC @Controller programming model -->
	<!-- Spring MVC @Controller 프로그래밍 모델을 활성화한다. -->
	<annotation-driven />
	<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
	<!-- ${webappRoot}/resources 디렉토리에서 정적 리소스를 효율적으로 제공하여 /resources/**에 대한 HTTP GET 요청을 처리한다. -->
	<resources mapping="/resources/**" location="/resources/" />
	<!-- src/main/resources/ -->
	<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
	<!-- /WEB-INF/views 디렉토리의 .jsp리소스에 대한 @Controllers의 렌더링을 위해 선택한 보기를 해결한다. -->
	<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
	<!-- 위의 경로를 바탕으로 클래스를 생성 후, 스프링 컨테이너에 bean(자바 객체)을 등록하겠다. -->
		<beans:property name="prefix" value="/WEB-INF/views/" />
		<!-- 위 클래스의 속성이 prefix(접두사)인 애에게 value를 넣어준다. -->
		<beans:property name="suffix" value=".jsp" />
		<!-- 접미사로 .jsp -->
	</beans:bean>
	
	<context:component-scan base-package="com.kh.template" />
	<!-- src/main/java/com.kh.template/HomeController 을 스캔하라. 이게 없으면 HS 에 S가 사라짐 -->
	
	
	
</beans:beans>
package com.kh.template;
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
//@Controller : 컴포넌트로서 스캔가능하게 한다. 없으면 S가 사라짐
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";
	}
	
}
컨트롤러 생성
jsp 생성
컨트롤러 등록, 연동
src/main/java/com.kh/app03.controller/MyController.java메소드 접근제한자는 무조건 public
return 값은 주소를 가지고 있어야 한다.
매개변수는 있어도 되고, 없어도 된다.
메소드 이름은 자유
package com.kh.app03.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.kh.app03.common.UrlHandler; @Controller public class MyController { /* * 1. 메소드 접근제한자는 무조건 public 2. return 값은 주소를 가지고 있어야 한다. 3. 매개변수는 있어도 되고, 없어도 된다. 4. 메소드 이름은 자유 * */ @RequestMapping(value = "/home") public String home() { return new UrlHandler().urlHandle("home"); } @RequestMapping("/test") public String test() { return new UrlHandler().urlHandle("test"); } @RequestMapping("/join") public String join() { return new UrlHandler().urlHandle("join"); } }
package com.kh.app03.common;
public class UrlHandler {
	public String urlHandle(String str) {
		return "/WEB-INF/views/" + str + ".jsp";
	}
}
	<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
 	<resources mapping="/resources/**" location="/resources/" />
	<!-- 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>
package com.kh.app03.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller public class MyController { /* * 1. 메소드 접근제한자는 무조건 public 2. return 값은 주소를 가지고 있어야 한다. 3. 매개변수는 있어도 되고, 없어도 된다. 4. 메소드 이름은 자유 * */ @RequestMapping(value = "/home") public String home() { return "home"; } @RequestMapping("/test") public String test() { return "test"; } @RequestMapping("/join") public String join() { return "join"; } }

package com.kh.app05.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("/member")
public class MemberController {
	//get일 때만 처리하게끔 아래처럼
//	@RequestMapping(value = "/join", method = RequestMethod.GET)
	@GetMapping("/join")
	public String join() {
		System.out.println("join get 요청 처리함");
		// get+post해서, 구분을 안해놔서 두번 나옴
		// 페이지 로딩할때, submit할 때
		return "member/join";
	}
	
	//post일 때만 처리하게끔 아래처럼
//	@RequestMapping(value = "/join", method = RequestMethod.POST)
	@PostMapping("/join")
	public String join2() {
		System.out.println("join post 요청 처리함");
//		회원가입 성공하면 아래로
		return "member/join_result";
	}
}
<%@ 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>
	<h1>join</h1>
	<form action="join" method="post">
		<!-- id, pwd, nick -->
		id : <input type="text" name="id"><br>
		pwd : <input type="text" name="pwd"><br>
		nick : <input type="text" name="nick"><br>
		<input type="submit" value="가입">
	</form>
</body>
</html>         

