大家帮我看看哪不对了,为什么不输出结果呢?
写了一个简单的身份验证,可是我无论输什么,他都输出"123", 大家帮我看看这是怎么回事?<%@ page contentType="text/html; charset=gbk" language="java" errorPage="" %>
<%@page import ="java.sql.Connection" %>
<%@page import ="java.sql.DriverManager" %>
<%@page import ="java.sql.SQLException" %>
<%@page import ="java.sql.Statement" %>
<%@page import ="java.sql.ResultSet" %>
<%!
String usrName,usrPassword;
boolean loginAttempt = false;
%>
<%
if(request.getParameter("name") != null && request.getParameter("passwd")!=null)
{
loginAttempt=true;
}
if(!loginAttempt)
{
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
Connection conn = DriverManager.getConnection("jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test","sa","sa");
if(!conn.isClosed())
{
out.println("成功连接");
usrName=request.getParameter("name");
usrPassword=request.getParameter("passwd");
String sql="SELECT * FROM test WHERE name='"+usrName+"'";
Statement stmt=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_UPDATABLE);
ResultSet rs=stmt.executeQuery(sql);
if(rs.next())
{
if(usrPassword.equals(rs.getString("passwd")))
out.println("ok");
else
out.println("no");
}
rs.close();
stmt.close();
}
conn.close();
}
else
out.println("123");
%>
<html>
<body>
<form action="#" />
<input type="text" name="name"/>
<input type="text" name="passwd"/>
<input type="submit" value="确定"/>
<input type="reset" value="撤销"/>
</form>
</body>
</html>