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 |
Tags
- 알고리즘
- 자바
- Vue.js
- 뷰
- SBS 개발
- 사내시스템
- URL입력
- 첫 리액트
- react
- 대문자
- 첫 React
- e-HR
- IT시스템개발
- 리액트
- 백준
- 뷰 리액트 비교
- 뷰 리액트
- SBS 본사
- 오라클
- 트리
- CompositionAPI
- 경력직
- 쟈스
- 백준알고리즘
- 면접
- MySQL
- 프로젝트 후기
- 간단 프로젝트
- 1차면접
- 웹 개발 면접 질문
Archives
- Today
- Total
리주의 프로그래밍 공부
정적파일 서비스 본문
정적인 리소스 : 이미지, html, js, css 등
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
위의 코드에서 url-pattern에 있는 /가 jsp만 통과시키고 정적인 파일은 제한
정적인 파일을 서비스하기 위해서 -servlet.xml 파일을 다음과 같이 수정
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="/index" class="com.newlecture.web.controller.IndexController"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
</beans>
위의 코드(기존 -servlet.xml)에서 3줄 추가(17번째 줄은 예시)
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/mvc
https://www.springframework.org/schema/mvc/spring-mvc.xsd">
<bean id="/index" class="com.newlecture.web.controller.IndexController"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
// location : 물리적 폴더 경로 mapping : 접속 url 패턴
<mvc:resources location="/static/" mapping="/**"></mvc:resources>
</beans>
3번째줄 : "http://www.springframework.org/schema/mvc" 를 mvc로 치환한다고 생각하면 편함(namespace)
17번째줄 : 리소스 요청이 들어오는 url을 /static/으로 보냄
'스프링(Spring) 공부' 카테고리의 다른 글
| DI를 Annotation으로 변경 (0) | 2021.01.06 |
|---|---|
| 설정파일 분리하기 (0) | 2021.01.05 |
| 연결정보 분리 (0) | 2021.01.05 |
| Wildcard (0) | 2021.01.04 |
| ViewResolver (0) | 2020.12.31 |