Src path problem when HTML files under WEB-INF refer to JS files outside WEB-INF

Problem Description

This is a problem encountered when working on a project
following the MOOC video : In the video, the teacher used this when importing the js file in shopoperation.html:

<script type='text/javascript' 
src='../resources/js/shop/shopoperation.js' charset='utf-8'></script>

Then the project structure diagram is like this:
Insert picture description here
The path where shopoperation.html is located is'src/main/resources/webapp/WEB-INF/html/shop', if you use'.../' to indicate that you return to the upper level directory, you should return to ' src/main/resources/webapp/WEB-INF/html', but

<script type='text/javascript'
		src='../resources/js/shop/shopoperation.js' charset='utf-8'></script>

It feels like you returned to the webapp directly after using'…/'? This contradicts my cognition.

problem solved

Find the answer in the answer of the MOOC course: the
path is based on the path actually released by Tomcat, not the path of the project seen on eclipse.
After starting Tomcat, click F12 on the page to view the project structure:
Insert picture description here
if the project published on tomcat prevails, the path to the back of'…/' is o2o (the name of the project I made), then src='…/ resources/js/shop/shopoperation.js' can naturally find the shopoperation.js file.
The URL to visit this page is http://localhost:8080/o2o/shopadmin/shopoperation. Maybe the path of the Tomcat release project is the path in the URL?

verification

The upper part made further verification:
the

<script type='text/javascript' 
src='../resources/js/shop/shopoperation.js' charset='utf-8'></script>

The path in is changed to

<script type='text/javascript'
src='/o2o/resources/js/shop/shopoperation.js' charset='utf-8'></script>

The JS file was still found correctly.
Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_38404857/article/details/109961129