[Tomcat / 톰캣] HTTP Error 404 “The Requested Resource Is Not Found”

sbj·2023년 11월 23일
0

ERROR.zip

목록 보기
1/19
post-thumbnail

Problem (문제)

It's a terrible error. I struggled with this error for nearly a few days.
끔찍한 에러. 404 에러랑 하루종일 싸웠다.


Cause (원인)

I'm not sure. Let's first look into the reason why the 404 error occurs.

  • The domain no longer exists.
    도메인이 더 이상 존재하지 않을 때.
  • The requested resource has been deleted or moved to a different URL.
    요청된 리소스가 삭제되었거나, 다른 URL로 이동되었을 때.
  • The URL was mistyped into the browser.
    URL이 브라우저에 잘못 기입되었을 때.

Problem Solving Process (문제해결과정)

  1. Check the URL.

Check if the HTML is correcrtly mapped to be displayed on the screen.

@GetMapping("/main")
	public String main() {
		return "main";
	}
}
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<link href="css/styles.css" rel ="stylesheet"/>
</head>
<body>
<h1>Welcome</h1>
</body>
</html>
  • This is the Controller and HTML page. There are no issues with file path or file name.
    Controller, HTML 페이지이다. 파일 경로와 파일명에는 문제가 없다.

  1. Check the Tomcat server.
    톰캣 서버 Port number 확인

Check the post number on the tomcat server.
톰캣 서버 Port number를 확인한다.
경로: Server -> Modules -> Port Number

  • There's no problem. The server port number is correctly set to 8090.
    문제 없다. 톰캣 서버 8090으로 정확히 설정되어 있다.

  1. Change the Tomcat General ➡️ Location settings.

경로: General -> Switch Location


  1. Project ➡️ Web Project Settings ➡️ Context root.

  • Change the context root to /
    Project ➡️ Web Project Setting ➡️ Context root "/" 로 변경해준다.

  1. Check the JDK path.
    JDK 경로 확인

  • Change the JDK version
    Preference ➡️ Installed JREs

  1. CHeck the JDK Compiler Compliance Level and JDK Version.
    JDK 컴파일러 확인

  • Check the Java version
    자바 버전까지 확인해준다.

  1. Check the Java version compatible with Tomcat.
    톰캣과 호환 가능한 Java 버전 확인

All my efforts were in vain.
I’m currently using Spring Boot version 3.1.5 (3.x.). It’s okay to use Java version 17.
I think I need to reconfigure the Tomcat version.
Looking at the Tomcat homepage, it seems I should be using Tomcat version 10.x. I was deploying on Tomcat 9.
Could this have been the issue?

현재 스프링 부트 3.1.5 버전을 사용하고 있고, Java 17 버전과 호환 가능하다.
아무래도 톰캣을 재구성해야할까 싶다.


  1. Switch to Tomcat version 10.1x
    톰캣 버전 변경

The Spring project is not being deployed on the Tomcat server at all.
스프링 프로젝트가 톰캣에 전혀 올라가지 않는다.


  1. Edit Tomcat server.xml
    톰캣 server.xml 수정
<Listener SSLEngine="on" className="org.apache.catalina.core.AprLifecycleListener"/>
  • I commented out this tag. This tag is a listener that connects messages from the outside to Apache. However, the error still remains unresolved.
    외부 메시지를 Apache에 연결하는 리스너인 해당 태그를 주석처리 해주었다.여전히 에러는 해결되지 않는다.

  1. Edint Tomcat server.xml (2)
    톰캣 server.xml 수정 (2)

  • Check the path in server.xml
    path가 "/"으로 설정되어 있는지 확인해준다.

  1. Reconfirm Java environment variables
    자바 환경변수 확인

🤦🏻‍♀️

  • Check the Java environment variables.
    자바 환경변수 확인

📍 Reason for setting environment variables (환경변수를 설정하는 이유)

In order to use tools such as javac, java, etc., one needs to navigate to the path where the tool is located and execute it. To avoid this inconvenience and allow execution from any path, we set up environment variables.
Java, javc 툴 사용하기 위해선 해당 경로로 이동하여 실행해야 하는데, 환경변수를 설정하면 번거로움을 줄이고 어떤 경로에서든 실행할 수 있다.


  1. 파일 경로 확인

/dbConnectionTest/src/main/webapp/login.html

[localhost:8081/login.html]로 이동하고자 했고, HTTP 404 에러가 떴었다.
원인은 webapp 폴더가 아닌 webapp/WEB-INF 폴더 안에 있었기 때문이다.


Result (결과)

It took me three hour to display "Hello World."
The issue was with the Java environment variables, which is embarrassing. There was no problem with the tomcat server connection.
I must ensure that such a ridiculous error does not occur again.

"Hello World"를 출력하는데 세 시간이 걸렸다. 문제는 자바 환경변수였다. 부끄럽다. 톰캣 서버에는 문제가 없었다.
다시는 이런 얼토당토 않은 일이 없도록 해야한다.

profile
Strong men believe in cause and effect.

0개의 댓글