读书人

快帮帮小弟我吧

发布时间: 2012-01-06 22:55:18 作者: rapoo

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

读书人网 >Java Web开发

热点推荐