gistfile1.txt package stringescapeutils; import org.apache.commons.lang.StringEscapeUtils; public class StringEscapeUtilsTest { public static void main(String args[]){ String sql="1' or '1'='1"; System.out.println("防SQL注入:"+StringEsca
package stringescapeutils; import org.apache.commons.lang.StringEscapeUtils; public class StringEscapeUtilsTest { public static void main(String args[]){ String sql="1' or '1'='1"; System.out.println("防SQL注入:"+StringEscapeUtils.escapeSql(sql)); //防SQL注入 System.out.println("转义HTML,注意汉字:"+StringEscapeUtils.escapeHtml("chen磊 xing")); //转义HTML,注意汉字 System.out.println("反转义HTML:"+StringEscapeUtils.unescapeHtml("chen磊 xing")); //反转义HTML System.out.println("转成Unicode编码:"+StringEscapeUtils.escapeJava("陈磊兴")); //转义成Unicode编码 System.out.println("转义XML:"+StringEscapeUtils.escapeXml("陈磊兴 ")); //转义xml System.out.println("反转义XML:"+StringEscapeUtils.unescapeXml("陈磊兴 ")); //转义xml } } 输入结果: 防SQL注入:1'' or ''1''=''1 转义HTML,注意汉字:chen磊 xing 反转义HTML:chen磊 xing 转成Unicode编码:\u9648\u78CA\u5174 转义XML:陈磊兴 反转义XML:陈磊兴