在java中转义javascript字符串 [英] Escaping javascript string in java
本文介绍了在java中转义javascript字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
< script type =text / javascript> document.write(< img src = \UpArrow.png \/> \); < /脚本>
有人可以帮忙吗?我继续尝试,最终这样...
返回< script type = \text / javascript\\ \\> document.write(\< img src = \UpArrow.png \/> \);< / script>;
哪些不起作用,因为我需要在UpArrow.png之前和之后双重转义引号。因为它需要在JavaScript中转义,而不是在java中。
解决方案
Apache commons在 StringEscapeUtils : escapeJavaScript
方法。
I need to make this into a string in java:
<script type="text/javascript">document.write("<img src=\"UpArrow.png\" /> \"); </script>
Can someone help? I keep trying and it ends up like this...
return "<script type=\"text/javascript\">document.write(\"<img src=\"UpArrow.png\" /> \"); </script>";
Which doesn't work because I need to double escape the quotes before and after UpArrow.png. since it needs to be escaped in javascript and not in java.
解决方案
Apache commons have a methods just for this in StringEscapeUtils : the escapeJavaScript
method.
这篇关于在java中转义javascript字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文