求教!identity判断失误
我想实现通过判断账号密码和身份三个条件有不同的登录效果,下面是我的代码(非常不规范,请见谅!)
start.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page import ="java.sql.*"%>
<%@ page import="java.io.*"%>
<%@ page import ="java.util.*"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>login</title>
</head>
<body>
<table width="694" align="center">
<tr>
<th scope="col"><form id="form1" name="form1" method="post" action="login.jsp">
<table width="652">
<tr>
<th width="50" scope="col">账户</th>
<th width="175" scope="col"><label>
<input type="text" name="account" />
</label></th>
<th width="51" scope="col">密码</th>
<th width="177" scope="col"><label>
<input type="password" name="password" />
</label></th>
<th width="52" scope="col">身份</th>
<th width="71" scope="col"><select name="identity">
<option value="供应商">供应商</option>
<option value="管理员">管理员</option>
</select>
</th>
<th width="44" scope="col"><input type="submit" name="Submit" value="登录" /></th>
</tr>
</table>
</form>
</th>
<th scope="col"><form id="form2" name="form2" method="post" action="register.jsp">
<input type="submit" name="Submit2" value="注册" />
</form>
</th>
</tr>
</table>
</body>
</html>
login.jsp
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ page import ="java.sql.*"%>
<%@ page import="java.io.*"%>
<%@ page import ="java.util.*"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>login</title>
</head>
<body text="#FF0000">
<div align="center">
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
String url= "jdbc:mysql://localhost:3306/graduationproject?user=root&password=123";
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String account = request.getParameter ( "account" );
String password = request.getParameter ( "password" );
String identity = request.getParameter ( "identity" );
String sql = "select * from identity where account='" + account + "' and password = '" + password + "'";
ResultSet rs = statement.executeQuery ( sql );
if( rs.next ( ))
{
String identity1=rs.getString("identity");
if(identity.equals(identity1)&&identity.equals("供应商") )
{
response.sendRedirect("supplier_page.jsp");
}
else if (identity.equals(identity1)&&identity.equals("管理员"))
{
response.sendRedirect("manu.jsp");
}
else if(!identity.equals(identity1))
{ %>
<strong>身份不正确!</strong>
</div>
</div>
<meta http-equiv="refresh" content="5;URL=start.jsp">
<div align="center">
<% }
}
else
{ %>
<strong>账号或密码不正确!</strong> </div>
<meta http-equiv="refresh" content="5;URL=start.jsp">
<% }
rs.close ( );
statement.close ( );
connection.close ( );
%>
</body>
</html>
账号或密码不正确的情况可以实现,但账号和密码都正确,身份不管正确或不正确,都会显示“身份不正确!”
是哪里的问题?请指教?
[解决办法]
把两个identity显示出来看看吧,最直接的排查方法。