有时候我们做网站后台的时候需要把用户的输入内容进行处理,避免恶意脚本的攻击。

以下列出了替换类

 1 public String toHTML(String value) {
 2         if (value == null){
 3             value = "";
 4         }
 5         value = value.replaceAll("&", "&");
 6         value = value.replaceAll("<", "&lt;");
 7         value = value.replaceAll(">", "&gt;");
 8         value = value.replaceAll("\"", "&quot;");
 9         value = value.replaceAll("\n", "<br>");
10         return value;
11     }

 

posted on 2017-10-16 15:13  莫小伟  阅读(186)  评论(0)    收藏  举报