login.jsp登录页面
<%@ page language="java" pageEncoding="gb2312"%>
登录验证页面check.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="gb2312"%>
<%
String user=request.getParameter("user");
String pwd=request.getParameter("pwd");
String driverName="com.mysql.jdbc.Driver";
String username="root"; //数据库用户名
String password="123"; //密码
String dbName="student"; //数据库名
String tableName="book"; //表明
String url="jdbc:mysql://localhost:3306/"+dbName+"?user="+username+"&password="+password;
Class.forName(driverName).newInstance();
Connection conn=DriverManager.getConnection(url);
String sql="select * from "+tableName+" where user='"+user+"' and pwd='"+pwd+"';
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery(sql);
if(rs.next())
{ response.sendRedicrect("success.jsp"); //验证通过跳转到..
}else
{ response.sendRedicrect("false.jsp"); //验证失败腿转到...
}
rs.close();
stmt.close();
conn.close();
%>