05 정적 컨텐츠

bourbon·2021년 12월 13일

Spring

목록 보기
6/14
post-thumbnail

스프링 웹개발 방법

  • 정적 컨텐츠 : 파일 자체를 웹 브라우저에 전달
  • MVC와 템플릿 엔진 : server에서 html파일로 변형 후 전달
  • API : JSON과 같은 데이터 구조 포멧으로 client에게 전달, server끼리 통신할 때 사용

정적 컨텐츠 구현

스프링 부트는 static을 찾아 정적컨텐츠 제공 기능을 자동 지원한다.

hello-spring/src/main/resources/static/hello-static.html

<!DOCTYPE html>
<html lang="en">
<head>
    <title>static content</title>
    <meta http-equiv="Content-Type" content="text/html; charset=Utf-8" />
</head>
<body>
정적 컨텐츠 입니다.
</body>
</html>

해당 코드를 실행 후 브라우저에 localhost:9090/hello-static.html을 입력하면 아래와 같이 "정적 컨텐츠 입니다." 라는 화면을 보여준다.


정적 컨텐츠의 구조


1. 웹 브라우저에서 톰캣이 해당 요청을 받음.
2. 톰캣은 스프링 컨테이너에 요청이 왔음을 알림.
3. 스프링 부트에서는 controller가 우선 순위에 있으므로, 가장 먼저 해당 파일과 관련된 controller를 찾음.
4. 해당 controller가 없으면 resources/static에 있는 관련 html파일을 찾아서 반환함.


profile
Do things that don't scale

0개의 댓글