jspx script element on GlassFish v3
Asked Answered
S

4

2

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"/> 
...
Sven answered 13/1, 2010 at 17:6 Comment(0)
S
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.

Sven answered 13/1, 2010 at 17:16 Comment(1)
For what it's worth, this is the solution that IBM officially endorses if you're stuck using Websphere Application ServerPerceptual
B
3

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:

<script ...><!-- keep open/close tags --></script>

It is still ugly, though.

Bushel answered 28/1, 2010 at 19:43 Comment(1)
Work for Tomcat (6) but not for Websphere (7).Metaphor
G
0

A potentially cleaner solution would be to create a custom taglib that outputs correct HTML, e.g.:

<m:htmlScript type="text/javascript" src="/js/jquery-1.4.4.min.js"/>

producing:

<script type="text/javascript" src="/js/jquery-1.4.4.min.js">

Another alternative would be to encapsulate the tag in CDATA:

<![CDATA[<script type="text/javascript" src="/js/jquery-1.4.4.min.js"></script>]]>

I covered this topic in more detail here: How to produce valid HTML with JSPX? (not XHTML)

Godwit answered 9/1, 2011 at 14:40 Comment(0)
A
0

Yet another ugly solution:

<tag>${null}</tag>
Audriaaudrie answered 31/8, 2012 at 13:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.