spring index.jsp 시작페이지 설정
안녕하세요~
여러분은 localhost:8080/ 을 검색했을때, index.jsp 파일을 보여주고 싶다면 어떻게 해야하는지 알고 계신가요?
바로 web.xml 에 설정을 해주면 됩니다.
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- 시작페이지 설정 --> <welcome-file-list> <welcome-file>/index.jsp</welcome-file> </welcome-file-list> ..... </web-app> | cs |
이렇게 말이죠.
이 부분에 대해 설명이 좀 필요할 듯 합니다.
spring은 과연 어떻게 많고 많은 파일 중, index.jsp의 위치를 찾아서 열 수 있을까요?
welcome-file-list 태그는 Doucument Root 를 읽게 되어있습니다.
즉, Document Root/index.jsp 를 읽는것이죠.
만약 없다면? 안읽히겠죠?
제 프로젝트의 구조는 어떨까요?
사진을 보면, index.jsp 의 위치는 src/main/webapp 아래 있습니다.
그렇다면 저희는 src/main/webapp이 Document Root 라고 추측할 수 있겠네요.
네, 맞습니다.
Spring을 사용할 때, 톰켓이 기본적으로 바라보고 있는 경로는 src/main/webapp이기 때문입니다.
그렇다면 만약 welcome-file을 WEB-INF 아래 있는 index.jsp로 하고 싶다면 어떻게 등록해야 할까요?
1 2 3 4 5 6 7 8 9 10 11 12 13 | <?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <!-- 시작페이지 설정 --> <welcome-file-list> <welcome-file>/WEB-INF/index.jsp</welcome-file> </welcome-file-list> ..... </web-app> | cs |
이렇게 등록해주면 Document Root/WEB-INF/index.jsp를 읽게되겠습니다.
시작페이지를 설정하는 방법 어렵지 않죠?
다음에는 계속해서 말한 Document Root가 어디에 설정되어 있고, 어떻게 변경할 수 있는지에 대해 말씀드리겠습니다.
그럼 이만~
'Web' 카테고리의 다른 글
Include 지시어와 Include 액션의 차이 (0) | 2019.01.27 |
---|---|
Tomcat8 Document Root (0) | 2019.01.19 |
Spring java.util.zip.ZipException: error in opening zip file 에러 (1) | 2019.01.08 |
Spring Tomcat 404 에러 (0) | 2019.01.07 |
Redirect와 Forward 차이 (0) | 2018.12.10 |