spring legacy project: resources 경로

김선미·2022년 12월 16일

css 파일이 커져서 파일을 분리하고 싶은데 spring legacy project는 스프링 부트 프로젝트와 달리 static, templates 폴더가 없어서 어디로 경로 설정을 해주어야 하는지 찾아보았고 아래 방법으로 해결하였다.

servlet-context.xml 확인

	<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
	<resources mapping="/resources/**" location="/resources/" />
  • 경로가 위와 같이 되어있으면 리소스의 상위 폴더가 resources 여야 한다.
  • 즉 경로는 "/resources/하위 폴더 또는 파일명" 이 된다.

폴더 구조 확인

  • 폴더 구조는 현재 JSP 파일과 호출한 css 파일이 다른 폴더에 있었다.
  • webapp
    • resources
      • userpage.css
    • WEB-INF
      • spring
      • view
        • userpage.jsp
      • web.xml
  • 이때는 상위 폴더를 한번 벗어날때마다 경로에 점 두개 ..를 추가한다.
  • 즉 나의 경로 소스 코드는 아래와 같다.
<link rel="stylesheet" href="../resources/userpage.css">

경로에 대해서는 필요할 때마다 더 찾아보아야겠다.

참고

profile
백엔드 개발 공부

0개의 댓글