Class.forName(mysqlDriver); conn=DriverManager.getConnection(connStr,"root",""); Statement stmt=conn.createStatement(); String sql="select * from login where where userID='"+logNameA+"' and password='"+passwdA+"' "; RS=stmt.executeQuery(sql); try{
while(RS.next()){ rowCountA++; }
if(rowCountA!=0) loginOKA=true;
} catch(Exception e) { e.printStackTrace(); } sql="select * from login where userID='"+logNameB+"'and password='"+passwdB+"' "; RS=stmt.executeQuery(sql); try {
你在sql语句之前out.print一下,看看有没有得到值!
唉,受不了了!
String logNameA,passwdA,logNameB,passwdB;
boolean loginOKA=false,loginOKB=false; if(request.getParameterValues("submit1")!=null){
logNameA=request.getParameter("nameA");
logNameB=request.getParameter("nameB");
passwdA=request.getParameter("passwdA");
passwdB=request.getParameter("passwdB");
//logNameA=getStr(logNameA);
//logNameB=getStr(logNameB);
//passwdA=getStr(passwdA);
//passwdB=getStr(passwdB);
int rowCountA=0,rowCountB=0;
String mysqlDriver="org.gjt.mm.mysql.Driver";
String connStr="jdbc:mysql://localhost/ca";
Connection conn=null;
ResultSet RS=null;
Class.forName(mysqlDriver);
conn=DriverManager.getConnection(connStr,"root","");
Statement stmt=conn.createStatement();
String sql="select * from login where where userID='"+logNameA+"' and password='"+passwdA+"' ";
RS=stmt.executeQuery(sql); try{
while(RS.next()){
rowCountA++;
}
if(rowCountA!=0) loginOKA=true;
}
catch(Exception e)
{
e.printStackTrace();
} sql="select * from login where userID='"+logNameB+"'and password='"+passwdB+"' ";
RS=stmt.executeQuery(sql);
try
{
while(RS.next()){
rowCountB++;
}
if(rowCountB!=0) loginOKB=true;
}
catch(Exception e)
{
e.printStackTrace();
} if ( loginOKA&&loginOKB ) {
session.setAttribute("adminA",logNameA);
session.setAttribute("adminB",logNameB);
response.sendRedirect("http://localhost:8080/admins/index.html"); }
else{ //提示用户登录错误信息 //管理员名或者密码不正确!
response.sendRedirect("http://localhost:8080/admins/error.html"); }
}%><html>
<head><title>管理员登录</title></head>
<body>
<br>
<br>
<h1><b><center>管理员登录</center><b></h1>
<br>
<form action="login.jsp" method="post" id="loginForm"><table align="center"cellspacing="30">
<tr>
<th><h3><b>管理员A</h3></b></th> <th></th>
<th><h3><b>管理员B</h3></b></th>
</tr>
<tr>
<td><center>姓名A:<input type="text"name="nameA"size="20"></center></td> <th></th>
<td><center>姓名B:<input type="text"name="nameB"size="20"></center></td>
</tr> <tr>
<td><center>密码A:<input type="password"name="passwdA"size="20"></center></td> <th></th>
<td><center>密码B:<input type="password"name="passwdB"size="20"></center></td>
</tr> <tr></tr> <tr>
<td align="right"><input type="submit" name="submit1"value="确定"size="20"</td> <th></th>
<td align="left"><input type="reset" name="reset1"value="取消"size="20"></td>
</tr> </table></form></body></html>
我用的是SQL Server,不太明白你的代码。
sql="select * from login where userID="+logNameB+" and password='"+passwdB+"'";
或者换成int试试??
logNameA= new String( logNameA.getBytes("ISO8859_1"),"gb2312");
试试看!!