Tomcat reports 404 when accessing html files

Tomcat reports 404 when accessing html files

Possible problems:

  1. (Main cause) Configuration issue: Make sure your web server (like Tomcat) is properly configured to map HTML files to the appropriate handlers. Normally, web servers map JSP files to JSP engines by default, but additional configuration may be required for HTML files. You can check your server's configuration files (such as the web.xml file in Tomcat) to ensure that the way HTML files are handled is properly configured. Tomcat will automatically intercept other files except jsp, so accessing html shows 404

  2. File Path Issues: Make sure the HTML file is in the correct location and has the correct file path. Confirm that your HTML file is indeed in the correct subdirectory of the web application directory and that you are using the correct URL to access it.

  3. URL mapping issues: If you are trying to access an HTML file via a URL, there may be a URL mapping issue. Make sure you are using the correct URL path to access the HTML file and that you don't have any other URL redirection or rewrite rules causing access issues.

  4. Caching Issues: Sometimes browsers may cache previous HTTP responses, causing you to still see 404 errors even after you have resolved the issue. You can try to clear your browser cache or use a different browser when accessing HTML files to troubleshoot cache issues.

Phenomenon:

  1. Both the html file and the jsp file are in the webapps directory, and the jsp file can be accessed, but 404 is displayed when accessing the html file.
  2. Create a folder under the webapps directory, create a new html file and a jsp file under this folder, you can access the jsp file, but accessing the html file shows 404.

solve:

Find the tomcat installation directory, conf directory -> web.xml, find the servlet-mapping tag, and make the following modifications:

About more than 430 lines

image-20230610205800618

Finally, record the access of breaking 50W

Reference blog: http://t.csdn.cn/1ruU9

Guess you like

Origin blog.csdn.net/m0_63324772/article/details/131146550