String sName = request.getParameter("userName");
String pwd = request.getParameter("password");
//连接mdb数据库,验证用户名密码是否正确
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
out.print("driver:"+e);
}
try{
String url="jdbc:odbc:jspdata";
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
String sql = "select * from userTable where userName='"+sName +"' and userPwd = '"+pwd+"'";
ResultSet rs = stmt.executeQuery(sql);
if(!rs.next()){
//查不出结果则返回到登录页面
response.sendRedirect("index.jsp");
}
else{
//将用户名记录到session中
session.setAttribute("userName", sName);
//登录主页面
request.getRequestDispatcher("main.jsp").forward(request, response);
}
}
catch(Exception e){
out.print(e);
}
String pwd = request.getParameter("password");
//连接mdb数据库,验证用户名密码是否正确
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e){
out.print("driver:"+e);
}
try{
String url="jdbc:odbc:jspdata";
Connection conn = DriverManager.getConnection(url);
Statement stmt = conn.createStatement();
String sql = "select * from userTable where userName='"+sName +"' and userPwd = '"+pwd+"'";
ResultSet rs = stmt.executeQuery(sql);
if(!rs.next()){
//查不出结果则返回到登录页面
response.sendRedirect("index.jsp");
}
else{
//将用户名记录到session中
session.setAttribute("userName", sName);
//登录主页面
request.getRequestDispatcher("main.jsp").forward(request, response);
}
}
catch(Exception e){
out.print(e);
}