通过HtmlUtils.htmlEscape(name)把特殊符号进行转义

 如果输入诸如 <script>alert('papapa')</script> 这样的字符,会导致网页打开就弹出一个对话框。 那么在转义之后,就没有这个问题了

String name = HtmlUtils.htmlEscape("<script>alert('papapa')</script>");  
System.out.println(name);  

String username = HtmlUtils.htmlUnescape(name);  
System.out.println(username);

输出结果:

1、&lt;script&gt;alert(&#39;papapa&#39;)&lt;/script&gt;
2、<script>alert('papapa')</script>

猜你喜欢

转载自www.cnblogs.com/lsc12-9/p/12021291.html