![]() |
#2
wzh5453946222011-05-25 22:14
|
login.jsp如下
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
<script type="text/javascript">
function check()
{
if(form1.name.value=="")
{
alert("请输入姓名!");
form1.name.focus();
return false;
}
if(form1.password.value=="")
{
alert("请输入密码!");
form1.password.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form name="form1" method="post" action="log.jsp" onSubmit="return check()">
<p>用户名:
<input type="text" name="name">
</p>
<p><br>
密 码:
<input type="password" name="password">
</p>
<p>
<input type="submit" name="Submit" value="提交">
<input type="reset" name="Submit2" value="清空">
<a href="regist.jsp" target="_blank">我要注册</a></p>
</form>
</body>
</html>
log.jsp如下:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<%
String name=request.getParameter("name");
String password=request.getParameter("password");
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance();
String url="jdbc:Microsoft:sqlserver://localhost:1433;DatabaseName=bbs";
String username="sa";
String pwd="sa";
Connection conn=DriverManager.getConnection(url,username,pwd);
Statement stmt=conn.createStatement();
String sql = "select * from yonghu where name='"+name+"' and mima= '" + password + "'";
ResultSet rs=stmt.executeQuery(sql);
int i = 0;
while(rs.next()){
i++;
}
if (i>0) {
response.sendRedirect("login_ok.jsp");
}
else
{
out.print("<script>alert('登录失败');location.replace('login.jsp');</script>");
}
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
无论我输入什么它都显示登入失败,我都无语了,请教高手,急急急。。。。。!!!