无法从 JSF 1.2 页面中的另一个 Web 应用程序加载 JavaScript

发布于 2024-12-15 06:35:34 字数 603 浏览 2 评论 0原文

我有一个资源 Web 应用程序,它只有静态内容,例如图像、CSS 和 JavaScript。

我在 JSF 页面内的另一个 Web 应用程序中使用这些资源,但由于某种原因,JavaScript 文件未正确加载。到目前为止,我已经看到了两种结果,要么 JSF 页面呈现得很奇怪(缺少大部分内容),要么页面看起来不错,但 JavaScript 不起作用。 CSS 和图像都正常。

我正在加载如下所示的资源,

<head>
    <link rel="stylesheet" type="text/css" href="http://localhost:8080/resources/css/styles.css" />
    <script type="text/javascript" src="http://localhost:8080/resources/js/utils.js" />
</head>

FireBug 显示所有内容均已正确加载。当 JavaScript 内嵌在 JSF 页面中时,它们可以正常工作。

我尝试过 Jetty 8 和 GlassFish 3,但结果几乎相同。有人对问题出在哪里有一些指示吗?

I have a resources web app, which only has static content, such as images, CSS and JavaScript.

I'm using these resources in another web app within JSF pages, but for some reason the JavaScript files are not loaded properly. I've seen two outcomes so far, either the JSF page renders weirdly (missing most of the content) or the page looks fine, but the JavaScript is not functional. CSS and images come alright.

I'm loading the resources like below

<head>
    <link rel="stylesheet" type="text/css" href="http://localhost:8080/resources/css/styles.css" />
    <script type="text/javascript" src="http://localhost:8080/resources/js/utils.js" />
</head>

FireBug shows that everything is loaded properly. The JavaScripts work fine when they are inline inside the JSF page.

I've tried with Jetty 8 and GlassFish 3, but results are pretty much same. Anyone got some pointers on what's the problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

同展鸳鸯锦 2024-12-22 06:35:34

自关闭

<script type="text/javascript" src="http://localhost:8080/resources/js/utils.js"></script>

但是,它在具有 application/xhtml+xml 内容类型的纯 XHTML 文档中有效,但这反过来不受 IE 支持。将 XHTML 作为 text/html 提供也被认为是有害的。

这与 Java/JSF 无关。

Self-closing <script> tag is not valid in HTML documents with text/html content type and the browser behaviour is undetermined. You need to close it with another tag:

<script type="text/javascript" src="http://localhost:8080/resources/js/utils.js"></script>

It's however valid in pure XHTML documents with application/xhtml+xml content type, but this is in turn not supported by IE. Serving XHTML as text/html is in turn considered harmful.

This has nothing to do with Java/JSF.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文