首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

快帮帮小弟我吧

2012-01-06 
快帮帮我吧!这是我写的一个检查用户名是否可用的代码!我现在只能把返回给用户的信息(如“此用户名已被使用!

快帮帮我吧!
这是我写的一个检查用户名是否可用的代码!我现在只能把返回给用户的信息(如“此用户名已被使用!”)放在一个单独的页面,然后重定位到这个单独的页面来显示信息。可我想把返回信息放在一个对话框里,而不是一个网页里,该什么办啊?各位大哥哥救救我啊!以下是我的代码:    
<%@     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 "));    
 
                      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())    
                      response.sendRedirect( "no.jsp ");    
                      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())    
                                              response.sendRedirect( "no.jsp ");    
                                              else        
                                              {    
                                              response.sendRedirect( "yes.jsp ");    
                                              }    
                                              con2.close();    


                                              }    
                                              catch(SQLException     e2)        
                                              {    
                                                                      out.print( "SQL异常! ");    
                                              }    
                      }    
          con.close();    
              }    
  catch(SQLException     e1)        
              {    
                      out.print( "SQL异常! ");    
}    
%>    
<head>    
<title> 用户名验证 </title>    
</head>    
<body>    
</body>    
</html>    


[解决办法]
用window.openwin()

热点排行