日期:2014-05-18  浏览次数:20745 次

还有一个不知道哪里错的错误!
下面一段是我检查用户名是否可用的代码!
<%@   page   contentType= "text/html;charset=GB2312 "   %>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=gb2312 ">
<%@   page   import= "java.sql.* "   %>

<%!
public   String   codeToString(String   str)
{//处理中文字符串的函数
    String   s=str;
    try
        {
        byte   tempB[]=s.getBytes( "ISO-8859-1 ");
        s=new   String(tempB);
        return   s;
      }
    catch(Exception   e)
      {
        return   s;
      }    
}
%>
<%//接收客户端提交的数据
  String   username=codeToString(request.getParameter( "username "));
  if(username==null)
      {
      %>
      <SCRIPT   LANGUAGE= "JavaScript ">
      <!--
      window.alert( "请输入用户名! ");
      window.close();
      //-->
      </SCRIPT>
      <%
      }

String   sqlStrings= "select   *   from     userstable     where   user_name= ' "+username+ " ' "   ;
  try  
        {
        Connection   con;
        Statement   sql;
        ResultSet   rs;
        Class.forName( "com.mysql.jdbc.Driver ");  
        con=DriverManager.getConnection     ( "jdbc:mysql://localhost:3306/JOB ", "root ", "1 ");
        sql=con.createStatement();
        rs=sql.executeQuery(sqlStrings);
        if(rs.first())
        {
%>
<SCRIPT   LANGUAGE= "JavaScript ">
<!--
alert( "该用户名已被其他用户注册! ");
window.close();
//-->
</SCRIPT>
<%
        }
else  
{
        String   sqlStringw= "select   *   from     userwtable     where       user_name= ' "+username+ " ' "   ;
try  
        {
Connection   con2;
        Statement   sql2;
ResultSet   rw;
Class.forName( "com.mysql.jdbc.Driver ");  
con2=DriverManager.getConnection( "jdbc:mysql://localhost:3306/JOB ", "root ", "1 ");
        sql2=con.createStatement();
        rw=sql2.executeQuery(sqlStringw);
if(rw.first())
{
%>
<SCRIPT   LANGUAGE= "JavaScript ">
<!--
alert( "该用户名已被其他用户注册! ");
window.close();
//-->
</SCRIPT>
<%
}
else  
{
%>
<SCRIPT &nbs