验证不能通过,每次输入用户名和密码都会直接转到错误页,高手们看一下,谢谢
<%@ page import="java.sql.*" %>
<%
boolean flag=false;
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}catch(ClassNotFoundException e){
out.print(e);
}
String name = request.getParameter("name"); //接收表单参数
String password = request.getParameter("password"); //接收表单参数
//连接数据库
try{
//获取当前站点的绝对路径
String strDirPath=getServletContext().getRealPath("/");
//将“\”替换为“/” 即:D:/WebTest
strDirPath=strDirPath.replace('\\','/');
//数据库连接字符串
String url = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="+strDirPath+"userdl.mdb";
//建立ODBC数据源连接
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
String sql = "SELECT * FROM denglu name='"+name+"' AND password='"+password+"'";
ResultSet rs = stmt.executeQuery(sql); //查询记录
if(rs.next()){ //如果记录不为空,则激活标记
flag=true;
}
rs.close();
stmt.close();
conn.close();
}catch(Exception ex){
out.print(ex);
}
%>
<%
if(flag){
%>
<jsp:forward page="ok.jsp"/>
<%
}else{
%>
<jsp:forward page="error.jsp"/>
<%
}
%>