jspx script element on GlassFish v3

南楼画角 提交于 2019-11-29 16:15:52

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.

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.

ooBartez

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)

Yet another ugly solution:

<tag>${null}</tag>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!