Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- 자바화면구현
- 자바수업
- 자바토글버튼
- 자바컨테이너
- 백준고양이자바
- 자바공부
- 1일1로그
- 자바이벤트
- 백준10171
- 화이자미열
- 백준자바 #백준10718
- 스터디
- 백준구구단
- 백준고양이
- java
- 백준2739
- 포장방스터디
- 화이자접종후기
- cs지식
- 화이자백신후기
- 컴퓨터공부
- 자바
- 자바조건문
- 백준10718자바
- 자바컴포넌트
- GUI
- 코로나백신
- 화이자1일차
- 백준 #백준알고리즘 #백준 Hello World #Hello World
- 2739자바
Archives
- Today
- Total
Salted Caramel
[수업 87일차] 21.12.13 /Spring 3/ 한글 인코딩 처리/03_MVC01 본문
coding/[2021.08.02~2022.01.24] 수업복습
[수업 87일차] 21.12.13 /Spring 3/ 한글 인코딩 처리/03_MVC01
꽃무늬라떼 2021. 12. 21. 23:55* Spring MVC 흐름
1. web.xml
- 클라이언트로부터 요청이 들어오면 해당 요청을 가장 먼저 처리하는 곳.
- 필터가 있다면 가장 먼저 반응을 하여 필터 작업을 진행하게 됨 ==> 한글 인코딩 처리
2. /WEB-INF/spring/root-context.xml
- /WEB-INF/spring/root-context.xml 로 이동을 함.
- 모든 서블릿에서 사용할 자원을 설정하는 공간.
- DB 연동을 이 곳에서 진행을 하게 됨.
3. DispatcherServlet
- 해당 요청에 대해서 DispatcherServlet 이 우선적으로 해당 요청을 가로챔.
- <init-param> 부분에 있는 servlet-context.xml 파일로 요청이 넘어감.
4. /WEB-INF/spring/appServlet/servlet-contect.xml
- servlet-context.xml 파일에서는 브라우저의 요청으로 그 요청을 처리할
controller 로 이어주는 역할을 함.
- 즉, servlet-context.xml 파일에서 HandlerMapping(URL-Mapping)작업이 진행됨.
- <annotation-driven /> 이라는 설정을 통하여 URL 매핑이 일어나게 됨.
- <annotation-driven /> 에 의해 @RequestMapping 을 사용할 수 있게 되고
@RequestMapping 에 지정된 URL로 웹 브라우저의 요청 URL이 매핑이 되게 됨.
한글 인코딩 처리
<!-- 한글 인코딩 설정 작업 -->
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>
Hello world!
</h1>
<P> The time on the server is ${serverTime}. </P>
</body>
</html>
@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);
model.addAttribute("hello", "Spring MVC 에 오신걸 환영합니다.");
return "home";
}
/*
* 스프링 MVC에서 Model(모델)이란???
* - 컨트롤러에 의해서 비지니스 로직이 수행이 되고 나면
* 대체적으로 view page에 보여질 정보들이 만들어짐.
* 이러한 정보들을 스프링에서는 Model(모델) 이라고 함.
* 이 Model(모델) 정보를 view page로 보내게 됨.
*/
@RequestMapping("/memberInfo")
public String member(Model model) {
model.addAttribute("name", "홍길동");
model.addAttribute("age", 27);
model.addAttribute("addr", "서울시 마포구 월드컵북로");
return "member";
}
같은 말.
return "member"
= /WEB-INF/views/member/jsp
member.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>
<div align="center">
<h2>회원 정보 페이지입니다.</h2>
<p>회원 이름 : ${name }</p>
<p>회원 나이 : ${age }</p>
<p>회원 주소 : ${addr }</p>
</div>
</body>
</html>
memberInfo 라고 뒤에 쳐주면
라고 나온다.
- property 속성
- 인자 생성자
'coding > [2021.08.02~2022.01.24] 수업복습' 카테고리의 다른 글
21.12.28 python 2 (0) | 2021.12.28 |
---|---|
21.12.27 Python1 (0) | 2021.12.27 |
[수업 88일차] 21.12.14 /Spring 4/ 04_MVC02/ 05_MVC03/ Spring 에서 바로 jsp 파일로 접근이 안되는 이유/root-context.xml/spring jdbctemplate (0) | 2021.12.16 |
[수업 86일차] 21.12.11 /Spring 2/ 스프링 라이브러리 파일/lombok 설치/ (0) | 2021.12.13 |
[수업 85일차] 21.12.10 / Spring 1 / 01_NonSpring/ 02_DI (0) | 2021.12.13 |