<%@page contentType="text/html;charset=gbk"%>
<%@page import="java.sql.*"%><%
String DBDriver = "com.mysql.jdbc.Driver";
String URL = "jdbc:mysql://localhost/mldn";
String DBUser = "root";
String DBPassword = "root";
Connection conn = null;
Statement stmt = null;
String sql = null;
ResultSet rs = null;
boolean bl = false;

String name = request.getParameter("uanme");
String password = request.getParameter("upass");
%><%
try {
Class.forName(DBDriver);
} catch(Exception e) {
out.println("数据库驱动程序加载失败");
}

try {
conn = DriverManager.getConnection(URL,DBUser,DBPassword);
} catch(Exception e) {
out.println("数据库连接失败");
}

try {
stmt = conn.createStatement();
} catch(Exception e) {
out.println("Statement创建失败");
}

sql = "select name from person where name ='"+name+"' and password='"+password+"'";
rs = stmt.executeQuery(sql);

if(rs.next()) {
bl = true;
}
System.out.println(bl);
try {
rs.close();
stmt.close();
conn.close();
} catch(Exception e) {
out.println("数据库关闭失败");
}

if(bl) {
%>
<jsp:forward page="login_success.jsp"/>
<%
} else{
%>
<jsp:forward page="login_failure.jsp"/>
<%
}
%>
%>
还有一个登录框就不写出来了,当我输入用户名和密码时,怎么也显示用户名密码错误,但是我把'"+name+"'和'"+password+"'改成数据库里有的数据时,点击这个页面就能正常登录,这是怎么回事呢?谢谢了

解决方案 »

  1.   

    你测试一下看看你程序里面接收到的name和password是不是你页面上面输进去的
      

  2.   

    也就是想一楼的那样呀,我的参数据传递出错啦,简单的说,你的表单提交出错啦,也就是要想正确的话,表单提交时,要刷新此页面啦,也即是<form onload="页面名"...>可明白啦!这样写,你不怕数据累死呀,是做毕业设计的吧!嗨,学习框架试一下啦!有好处的!
      

  3.   


    既然接受不到那就是你数据没传过来咯,你的登录页面jsp怎么写的阿?
    有没有form标签?两个文本框是不是被form标签包起来了?