오류 원인
이 오류는 대부분 경로문제라고 한다.
나는 다음에 나오는 3가지 방법을 다 써서 오류를 고칠 수 있었다.
오류 해결 - context root
대부분 tomcat의 context root의 경로가 틀렸기 때문에 에러가 났다고 한다.
따라서 Application context를 /로 바꾸었는데도 에러는 고쳐지지 않았다.
오류 해결 - web, WEB-INF
web 폴더에 직접적으로 존재하는 jsp 파일은 브라우저로 직접 접근이 가능하다.
하지만 WEB-INF 하위의 jsp 파일은 브라우저에서 직접 접근이 불가능한 경로라는 것이다...!!!
web과 WEB-INF 폴더의 차이를 알아보자.
web | WEB-INF | |
장점 | web 하위에 있을 경우 바로 jsp 파일을 볼 수 있다. | 유저의 직접 접근이 어려워 보안성이 높다. |
단점 | 보안이 취약하다. | 직접적으로 view를 볼 수 없다. <a> 앵커 태그로 이동이 불가하며 Controller를 통해서만 이동이 가능하다. |
정리하자면, 보안의 중요도에 따라 web의 하위에 둘지, WEB-INF에 둘지 정하면 된다.
오류 해결 - .iml 파일 경로
<root url="file://$MODULE_DIR$/web" relative="/" />
<root url="file://$MODULE_DIR$/../../web" relative="/" />
나같은 경우에는 webroots 에서 위의 코드에서 아래의 코드로 수정을 해주어 해결이 되었다.
추가적으로,
톰캣을 설치한 뒤 bootrun으로 실행하니 위와 같은 에러가 항상 떴다.
확인해보니 톰캣으로 실행시키지 않아 그런 것 같다.
헷갈리지말고 기억해두자!!
드디어 성공...!!
틀린 부분이 있으면 지적해주시면 감사하겠습니다.
Reference
[스프링개념] web과 WEB-INF 폴더에 관해서 및 WEB-INF에서의 앵커 태그 <a>에 관해서[Tomcat / IntelliJ] The origin server did not find a current representation for the target resource or is not willing to disclose that one exists. 404 error 해결하는 법
'Server' 카테고리의 다른 글
[tomcat] welcome-file 안 열림 오류 해결 (0) | 2024.09.24 |
---|---|
[ssh] not a directory 해결, ssh란? (0) | 2024.09.21 |
[JPA] 기본키 생성 전략 / @GeneratedValue (0) | 2024.08.25 |
[JPA] 영속성 컨텍스트 #2 (0) | 2024.08.08 |
[SpringBoot] Entity 생성하기 / JPA 간단한 예제 (0) | 2024.08.07 |