jspx script element on GlassFish v3

前端 未结 4 618
刺人心
刺人心 2020-12-21 15:51

The .war is served from GlassFish v3. I am trying to include a javascript file from my jspx.



        
相关标签:
4条回答
  • 2020-12-21 16:23

    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.

    0 讨论(0)
  • 2020-12-21 16:23

    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.

    0 讨论(0)
  • 2020-12-21 16:34

    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)

    0 讨论(0)
  • 2020-12-21 16:36

    Yet another ugly solution:

    <tag>${null}</tag>
    
    0 讨论(0)
提交回复
热议问题