如果输入诸如 <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、<script>alert('papapa')</script>
2、<script>alert('papapa')</script>