HTML File path not working

I have the following 3 folders:

image

My index.html is located inside resources-->public folder as shown below:

image

From this index.html, I am trying to refer the jquery-3.3.1.js, which is located inside webapp-->scripts folder as shown below:

image

In index.html, I tried the following but it didn’t work:

<script src="../webapp/scripts/jquery-3.3.1.min.js"></script>

What am I doing wrong?

That’s two folders deep then you will need 2 steps back (i.e. ../../)

e.g.

<script src="../../webapp/scripts/jquery-3.3.1.min.js"></script>

3 Likes

Thanks but for some reason, after making changes, it’s still not working :

Here is the screenshot of the changes I did :

However, when I uncomment this line and comment the HTML path line, it starts loading jQuery in the developer tools of Firefox :

<script src="//code.jquery.com/jquery-3.3.1.min.js"></script>

When you go to “index.html” what is the full URL in the browsers address bar?

If “public” is the root you may need to pull in resources server-side or move resources under the root.

1 Like

The URL is : http://localhost:8080/MyProject/index.html

where, MyProject is the name of my project in the Eclipse.

Initially my index.html was in webapp folder only and everything was working fine but for some reason we have to move index.html to the public folder.

You mean to say, I should move all things inside public folder?

Yes.

The public folder is usually the root folder for your online presence.

Ok. Which option would be good then:

  1. Move whole webapp folder inside public folder without touching the index.html, i.e. Keep index.html inside public folder and just move the webapp folder and then make file path adjustments ?

  2. Move the index.html also inside webapp folder and then keep this webapp folder inside public folder?

Usually at the simplest level the index.html sits inside the root folder (which is usually the public folder) and is then accessible by default. Then you would have your other folders lined up below.

e.g.

 Index.html
       folder1
       folder2

etc.

That’s how I usually do it for my own stuff but anything more complicated than that I leave to the experts :slight_smile:

Thanks.The following directory structure worked for me:

image

However when I tested it by moving webapp folder it didn’t work for some reason. I guess, I would stick with the working directory structure then.

Yes that looks about right :slight_smile:

1 Like

Great. Thanks for answering my questions !

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.