Mina Mina - 2 months ago 8x
jQuery Question

Dynamically adding an external JavaScript or CSS file in java web application

I want to add an external JavaScript or CSS file in my test.html dynamically.
I know about this trick:


rel: ‘stylesheet’,

type: ‘text/css’,

href: ‘**htttp://**javascripts/jwysiwyg/jquery.wysiwyg.css’


I want to save the url( of css and javascript on xml file for example web.xml, and read the url from web.xml file and append it to the href so if the url has to changed for example
the code in the html has'nt to be changed.

How shoud I write/read that url in the xml file and use it in the test.html?

  1. You can use javascript in your html page to load external javascript or css: http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml

  2. You need to dynamically generate html in order to change a part of it. You can use JSP for this. Define <context-param in your web.xml and then reference it in JSP page:


and then reference it in JSP:

<%= getServletContext().getInitParamter("someUrl") %>