날아라김지원

- JSP페이지에서 특정페이지로 리다이렉트하거나, 첫페이지를 바꿔야 하는 경우

ex) www.test.com  이 도메인 주소인데 www.test.com/user/login.vis  이런 페이지가 첫 화면이 되어야 한다면?

 

1. javascript이용하기

- index.html을 만들고

<script>
window.self.location = "user/login.vis"
</script>

이와같이 설정

 

2. jsp 문법 이용하기

<%
    response.sendRedirect("/user/login.vis");    
%>

혹은

<jsp:forward page="/user/login.vis">

 

3.web.xml 파일에서 welcome-file-list 설정하기

위와같이 1,2번을 사용하려고 해도 web.xml에 설정이 필요하다.

 

1,2번 방법은각각 html 파일과 jsp 파일을 이용하는 방법인데 아래와같이 web.xml에 먼저 설정해줄 필요가 있다.

 

그리고 web.xml파일은 tomcat서버쪽에 있기도하니 비교해서 사용하면 된다. 어느쪽에 넣어도 잘 작동하더라

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

파일리스트는 수정이 가능하다. 이렇게되면 우선순위로 위 파일들을 읽게되는데 index.html을 첫번 째에 넣으면

 

해당 파일을 먼저 읽게 된다. 나같은경우는 index.html을만들고 js를 통해 리다이렉트 설정을 했다.

 

  <!-- 시작페이지 설정 -->
    <welcome-file-list>
        <welcome-file>/WEB-INF/index.jsp</welcome-file>
    </welcome-file-list>

그리고 이와같이 경로를 통한 첫 페이지 설정역시 가능하다. 상황에 맞게 여러가지 방법을 활용하자

 

- 참고한페이지

https://h-coding.tistory.com/50

https://dololak.tistory.com/148

https://urakasumi.tistory.com/159

https://become.tistory.com/entry/spring-indexjsp-%EC%8B%9C%EC%9E%91%ED%8E%98%EC%9D%B4%EC%A7%80-%EC%84%A4%EC%A0%95

profile

날아라김지원

@flykimjiwon

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!