jsp数据库登陆校验

查询mysql数据库用户名密码跳转登陆成功或失败界面

<%
String user=request.getParameter(“username”);
String pass=request.getParameter(“password”);
//获取输入的用户名和密码
Class.forName(“com.mysql.jdbc.Driver”);
Connection conn=DriverManager.getConnection(“jdbc:mysql://localhost/congjiyong”,“root”,"");
//连接数据库
String sql=“select * from student where username=’”+user+"’ and password=’"+pass+"’";
//查询用户输入的用户名密码是否正确
//跳转成功界面或失败界面
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery(sql);
if(rs.next()){
response.sendRedirect(“success.jsp”);
}else{
response.sendRedirect(“failure.jsp”);
}
%>

猜你喜欢

转载自blog.csdn.net/CongJiYong/article/details/84707210