본문 바로가기
목차
Spring

Spring MVC (스프링 웹 MVC) 강의 10 - 정적파일 서비스하기

by 지각생 2022. 1. 4.
728x90

 

 

기본적으로 스프링이 정적인 파일 서비스 불가능하게 막아 놨기 때문이다.

 

/ 는

JSP말고 정적인 파일 막게 된다.

 

/*

로 설정해 두면 JSP도 막힌다.

 

 

<mvc:~~~~>태그를 쓰기 위해 

스키마 파일 등등 설정을 추가해줘야한다.


<?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">  
        <!-- collaborators and configuration for this bean go here -->
    </bean>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/view/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
<mvc:resources location="/resource" mapping="/resource/**"></mvc:resources>
</beans>


resource 폴더 생성

후 아무 이미지 파일 넣어서 실행해보면 

정적파일 실행되는 걸 확인할 수 있다.

 

 

다시 html폴더로 넣고 

html폴더명을 static으로 바꾼다

resource폴더 삭제

static이란 폴더 안에 정적인 파일들 다 모아둔다.

정적 이미지 실행하면 404에러가 뜬다

 

주소란에 static을 루트 취급하여 지우고 실행하면 404오류가 아닌 정상적으로 된다

그래서 최하단 index파일 실행하면

 정상적으로 불러와진다.

 

 

출처:

https://www.youtube.com/watch?v=-YHVKPbkSoM&list=PLq8wAnVUcTFWhDFFmpJ5fUeoJI53Z83g6&index=11 

 

 

728x90

댓글