- 博客(0)
- 资源 (1)
空空如也
登陆jsp数据库验证的代码
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>普通话水平测试报名系统</title>
</head>
<body>
<center>
<h1>普通话水平测试报名系统</h1>
<hr>
<br>
<br>
<%
//接收用户提交的参数
String username=request.getParameter("uname");
String userpassword=request.getParameter("upassword");
String userjb=request.getParameter("userjb");
//设置一个变量保存登录状态,ture表示登录成功,false表示登录失败
boolean flag=true;
%>
<%
String driverclass="com.mysql.jdbc.Driver";
String url="jdbc:mysql://localhost:3306/atao";
String uname="root";
String upass="958672";
Connection conn=null;
PreparedStatement stmt=null;
ResultSet rs=null;
Class.forName(driverclass);
conn=DriverManager.getConnection(url,uname,upass);
if(userjb.equals("1"))
{stmt=conn.prepareStatement("select * from users where user_id=? and userpass=? and role=?");
stmt.setString(1,username);
stmt.setString(2,userpassword);
stmt.setString(3,userjb);
rs=stmt.executeQuery();
if(rs.next())
{
flag=false;
}
if(flag){
%>
<script type="text/javascript" language="javascript">
alert("密码错误或无权限登录,请重新登录");
window.document.location.href="dl-index.jsp";
</script>
<%
}
else{
request.setCharacterEncoding("UTF-8");
session.setAttribute("uname",rs.getString(1));
session.setAttribute("upassword",rs.getString(2));
session.setAttribute("userjb",rs.getString(3));
response.sendRedirect("sgly/gg-index.jsp");
rs.close();
stmt.close();
conn.close();
}
}
if(userjb.equals("2"))
{stmt=conn.prepareStatement("select * from xxwyb where xxwy_id=? and password=? and role=?");
stmt.setString(1,username);
stmt.setString(2,userpassword);
stmt.setString(3,userjb);
rs=stmt.executeQuery();
if(rs.next())
{session.setAttribute("id",rs.getString(1));
session.setAttribute("pd",rs.getString(7));
flag=false;
}
if(flag){
%>
<script type="text/javascript" language="javascript">
alert("密码错误或无权限登录,请重新登录");
window.document.location.href="dl-index.jsp";
</script>
<%
}
else{
request.setCharacterEncoding("UTF-8");
session.setAttribute("uname",rs.getString(1));
session.setAttribute("upassword",rs.getString(2));
session.setAttribute("userjb",rs.getString(3));
response.sendRedirect("sxxwy/xx-ym.jsp");
rs.close();
stmt.close();
conn.close();
}
}
if(userjb.equals("0")){
%>
<script type="text/javascript" language="javascript">
alert("您还没有选择用户类型");
window.document.location.href="dl-index.jsp";
</script>
<%
}
%>
</center>
</body>
</html>
2015-04-28
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人