输入banner图图片脚本导航/分类

StringEscapeUtils的常用使用,防止SQL注入及XSS注入

StringBuffer sql = new StringBuffer("select * from users where 1=1 ");
String keyWord="aaa‘ or ‘1=1";
if(!keyWord.isEmpty()){
      sql.append(" and username like ‘%" + StringEscapeUtils.escapeSql(keyWord) + "‘");
}
System.out.println(sql);
技术图片

输出

select * from users where 1=1  and username like ‘%aaa‘‘ or ‘‘1=1‘

StringEscapeUtils.escapeSql会将1个‘转成2个‘,附源码:

技术图片

不进行转义的,会查出全部用户

select * from users where 1=1  and username like ‘%aaa‘ or ‘1=1‘ 

 

 

StringEscapeUtils的常用使用,防止SQL注入及XSS注入

标签:stringbu   copy   sql   where   ons   bar   use   用户   com