站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Java 专题通用防SQL注入函数java版

通用防SQL注入函数java版

摘要: 通用防SQL注入函数java版

</td> </tr> <tr> <td height="35" valign="top" class="ArticleTeitle">

通用防SQL注入函数java版

public static boolean sql_inj(String str)
{
String inj_str = "'|and|exec|insert|select|delete|update|count|*|%|chr|mid|master|truncate|char|declare|;|or|-|+|,";
String inj_stra[] = split(inj_str,"|");
for (int i=0 ; i < inj_stra.length ; i++ )
{
if (str.indexOf(inj_stra[i])>=0)
{
return true;
}
}
return false;
}

jsp中调用该函数检查是否包函非法字符
<%
if(request.getParameter("userID") != null)
userID = request.getParameter("userID").trim();

if (StringUtil.sql_inj(userID) || StringUtil.sql_inj(pwd)){
%>
<script Language=javascript>alert('参数中包含非法字符!');history.back(-1);</script>" ;
<%
}else{
……
}%>
StringUtil 是我的通用防注入函数的包名,该函数参考了ASP通用防SQL注入函数,做了一些修改。

</td> </tr> <tr>


↑返回目录
前一篇: Java Web中的入侵检测及简单实现
后一篇: 反连接代码