1

I have a project structure which looks like this

                  main
                  /   \
                 /     \
              conf    wwwroot
               /         \
              /           \
          header.jsp     assets
                            \
                             \
                              js
                               \
                                \
                               jquery.js

I need to include the jquery.js file in my header.jsp. I have tried

<script type="text/javascript" src="../wwwroot/assets/js/jquery.js"></script>

as suggested by some StackOverflow posts. However, this does not work. I cannot change the location of jquery.js as it is being used in several files within the "wwwroot" directory. Any help would be appreciated. Thank you.

UPDATE:

So the problem was that there was some internal routing happening inside the server which kept redirecting the requests. So, essentially, the script tag was looking in the wrong place.

  • 2
    Possible duplicate of [Browser can't access/find relative resources like CSS, images and links when calling a Servlet which forwards to a JSP](http://stackoverflow.com/questions/3655316/browser-cant-access-find-relative-resources-like-css-images-and-links-when-cal) – Anik Islam Abhi Oct 05 '16 at 11:28
  • 1
    Possible duplicate of [Link a .css on another folder](http://stackoverflow.com/questions/27218879/link-a-css-on-another-folder) – Bhojendra Rauniyar Oct 05 '16 at 11:32
  • Is your project hosted on IIS? – Nisarg Shah Oct 05 '16 at 11:44
  • No, it is not hosted on IIS. It is hosted on a private server. @NisargShah – Edwin Samuel Jonathan Oct 05 '16 at 11:47
  • Which folder contains web.config or app.config for this project? Because if it is in main folder, the src provided is wrong and it needs to be modified. – Nisarg Shah Oct 05 '16 at 11:50
  • It is within the conf folder @NisargShah – Edwin Samuel Jonathan Oct 05 '16 at 11:55
  • @EdwinSamuelJonathan, have you look into the duplicated ? You will find you answer there, after some reading of course. – AxelH Oct 05 '16 at 11:56
  • Your src seems to be working on my local machine when I try calling the same from the HTML page. So I think it has to do something with the rights. But you can always make a copy of jquery.js file in header.jsp, if that solution is feasible – Nisarg Shah Oct 05 '16 at 12:05
  • @AxelH I did search, but that didn't solve my problem. That's why I have asked the question. – Edwin Samuel Jonathan Oct 05 '16 at 12:11
  • 1
    @NisargShah I'm not too sure. Read permissions have been given to all files within the parent directory. – Edwin Samuel Jonathan Oct 05 '16 at 12:11
  • @EdwinSamuelJonathan did you tried copying the jquery.js file in same directory where header.jsp is there? – Nisarg Shah Oct 05 '16 at 12:14
  • @EdwinSamuelJonathan, you need to read and adapt the answer to your case. Once you will understand where is your file and where you need to go, you will be able to adapt the result. The first duplicate explain very well the problem and give all the solutions – AxelH Oct 05 '16 at 12:18
  • @NisargShah I did try that. So the problem is that there are multiple jquery.js and I'm not too sure. I will experiment and see. – Edwin Samuel Jonathan Oct 06 '16 at 03:45

2 Answers2

0

Can you please try below one:

src="../main/wwwroot/assets/js/jquery.js"

../ will navigate you to the immediate parent.

0

You can use this

  <script type="text/javascript" src="../../wwwroot/assets/js/jquery.js">    </script>

or

<script type="text/javascript" src="${pageContext.request.contextPath}/wwwroot/assets/js/jquery.js"></script>