GlassFish v3 上的 jspx 脚本元素
.war 由 GlassFish v3 提供。我正在尝试包含来自 jspx 的 javascript 文件。
<script type="text/javascript" src="/base/interface/Service.js"></script>
我在 http 响应中收到以下内容
<script src="/base/interface/Service.js" type="text/javascript" />
问题是它应该包含 标记。我相信这就是为什么它可以在 Chrome 上运行,但不能在 Firefox 或 IE 上运行。知道如何强制
更新:不确定这是否相关,但这是我的 jspx 文件的开头
<jsp:root version="2.0"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
xmlns:form="http://www.springframework.org/tags/form"
xmlns:spring="http://www.springframework.org/tags"
xmlns="http://www.w3.org/1999/xhtml">
<jsp:output doctype-root-element="html"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
<jsp:directive.page contentType="text/html" pageEncoding="UTF-8"/>
...
The .war is served from GlassFish v3. I am trying to include a javascript file from my jspx.
<script type="text/javascript" src="/base/interface/Service.js"></script>
I get the following in my http response
<script src="/base/interface/Service.js" type="text/javascript" />
The problem is that it should include the </script>
tag. I believe this is why it works on Chrome, but not on Firefox or IE. Any idea how to force <script></script>
Update: Not sure if any of this is pertinent, but here is the beginning of my jspx file
<jsp:root version="2.0"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
xmlns:form="http://www.springframework.org/tags/form"
xmlns:spring="http://www.springframework.org/tags"
xmlns="http://www.w3.org/1999/xhtml">
<jsp:output doctype-root-element="html"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
<jsp:directive.page contentType="text/html" pageEncoding="UTF-8"/>
...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我使用了
并保留结束标记。我认为这很丑陋,所以如果有人有更好的答案,我肯定会感兴趣。
I used
<script ...><jsp:text> </jsp:text></script>
and that retained the closing tag. I think this is ugly, so if anyone has a better answer I would definitely be interested.不幸的是,众所周知 jspx 会“最小化”空元素。在不向呈现的 HTML 添加空格的情况下防止最小化的一种方法是插入注释。例如:
尽管如此,它仍然很丑。
Unfortunately, jspx is known to "minimize" empty elements. One way to prevent the minimization without adding a space to the rendered HTML is to insert a comment. For example:
It is still ugly, though.
一个可能更简洁的解决方案是创建一个输出正确 HTML 的自定义标签库,例如:
生成:
另一种选择是将标签封装在 CDATA 中:
我在这里更详细地介绍了这个主题:
如何使用 JSPX 生成有效的 HTML? (不是 XHTML)
A potentially cleaner solution would be to create a custom taglib that outputs correct HTML, e.g.:
producing:
Another alternative would be to encapsulate the tag in CDATA:
I covered this topic in more detail here:
How to produce valid HTML with JSPX? (not XHTML)
还有一个丑陋的解决方案:
Yet another ugly solution: