开发者

Stop converting "<" to "&lt;" in jsp

I have jsp p开发者_开发技巧age and some set of javascript code written inside the jsp page.

for(i=0;i<10;i++)
{
//some stuff
}

but in the browser its giving error and the rendered code look like

for(i=0; i&lt;10; i++ { }

how to stop converting "<" to "&lt;".

Thanks in advance.


Is your JS code meant to be executed, or just displayed as it is?

If you have the former situation, is your code inside <script type="text/javascript">...</script> tags?

If you have the latter situation, then characters such as < HAVE to be converted to &lt, otherwise they would be read as HTML tags by your browser.


JSP does by default not do that. Aren't you actually using JSTL <c:out> to print JavaScript code? It can namely do that. You could disable that by adding escapeXml="false" attribute.

Anyway, best would always be to put JS code in its own .js file which you then include in the head as follows:

<script src="script.js"></script>


Hope this helps....

function toHtml(myString)
{
    htmlString = myString.split("&lt;").join("<");
    htmlString = htmlString.split("&gt;").join(">");
    htmlString = htmlString.split("&quot;").join("\"");
    htmlString = htmlString.split("&apos;").join("\'");
    return htmlString;
}

Gretting. Víctor

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜