I have few web pages sitting in different directories and my goal is to have some sort of organized structure so that I can access to js or css files without hardcoding the path.
For instance, the directory structure is:
root --- js --- some.js
|
|--css --- some.css
|
|---pages ---- main.jsp
|
|---other----foo---- foo.jsp
|
|--bar --- bar.jsp
Then main.jsp and foo.jsp tries to reference some.js but has to have different path.
( main.jsp )
<script type="text/javascript" src="../js/some.js"></script>
( foo.jsp)
<script type="text/javascript" src="../../js/some.js"></script>
This is not ideal if I want to change the location of main.jsp or foo.jsp, I have to come back to each files and change the path manually.
I am thinking to have factory class that has full path for each files so that it would look something like:
<script type="text/javascript" src=<% Factory.getFullPath(some.js) %> ></script>
In this case, I can still move files freely and not have to come back to each file.
Can I get some opinion to my approach? Is there other way to solve this?