我想在我的 test.html 中动态添加一个外部 JavaScript 或 CSS 文件。 我知道这个技巧:
$(”).appendTo(‘head’).attr({
rel: ‘stylesheet’,
type: ‘text/css’,
href: ‘**htttp://192.168.30.229:8080/**javascripts/jwysiwyg/jquery.wysiwyg.css’
});
我想将css和javascript的url(http://192.168.30.229:8080/)保存在xml文件例如web.xml中,并从web.xml文件中读取url并将它附加到 href 所以如果 url 必须更改,例如 **:http://192.168.100.229:7071/ html中的代码不用改
我应该如何在 xml 文件中写入/读取该 url 并在 test.html 中使用它?
最佳答案
您可以在您的 html 页面中使用 javascript 来加载外部 javascript 或 css:http://www.javascriptkit.com/javatutors/loadjavascriptcss.shtml
您需要动态生成 html 以更改其中的一部分。您可以为此使用 JSP。定义
<context-param
在您的 web.xml 中,然后在 JSP 页面中引用它:<context-param> <param-name>someUrl</param-name> <param-value>http://192.168.1.1:8080/something</param-value> </context-param>
然后在JSP中引用它:
<%= getServletContext().getInitParamter("someUrl") %>
关于java - 在 Java Web 应用程序中动态添加外部 JavaScript 或 CSS 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5923104/