servlets - jQuery scripts are not downloaded when the index page is opened on context root -


i have web application uses jquery ui. javascripts not downloaded , applied when browse context root directly , rely on welcome file:

http://localhost:8080/projectname/

but javascripts downloaded , applied when browse welcome file:

http://localhost:8080/projectname/myfiles/index.html

my project structure below:

 projectname `-- webroot     |-- myfiles     |   `-- index.html     `-- web-inf         `-- web.xml 

in web.xml, have defined welcome file index.html uses jquery ui.

<welcome-file-list>     <welcome-file>myfiles/index.html</welcome-file> </welcome-file-list> 

this can happen if path script source relative current request url, such example

<script src="jquery.js"></script> 

when open page by

http://localhost:8080/projectname/

then attempt download script from

http://localhost:8080/projectname/jquery.js

when open page

http://localhost:8080/projectname/myfiles/index.html

then attempt download script from

http://localhost:8080/projectname/myfiles/jquery.js

you use domain-relative path instead. assuming file indeed located in

http://localhost:8080/projectname/myfiles/jquery.js

then need declare script source follows

<script src="/projectname/myfiles/jquery.js"></script> 

or, dynamic resolving of context path subject changes outside control inside webapp's code

<script src="${pagecontext.request.contextpath}/myfiles/jquery.js"></script> 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -