login.jsp

来自「很不错的选课系统代码 很适合做 毕业论文参考 大家看看把」· JSP 代码 · 共 92 行

JSP
92
字号
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!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=gb2312">
<title>学生选课系统</title>
<style type="text/css">
<!--
body {
	background-image: url(image/bg_002.gif);
}
-->
</style></head>
<body>
<%
String name=(String)request.getParameter("username");
String pass=(String)request.getParameter("userpass");
String s=(String)request.getParameter("userselect");
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
String loginNum="0";
session.setAttribute("lnum",loginNum);
try
{
	Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
	conn=DriverManager.getConnection("jdbc:odbc:xk","sa","");
	if(s.equals("1"))
	{
		String sql="select * from student where sId='"+name+"' and sPass='"+pass+"'";
		stmt=conn.createStatement();
		rs=stmt.executeQuery(sql);
		if(rs.next()) 
		{
			loginNum="1";
			session.setAttribute("lnum",loginNum);
			session.setAttribute("name",name);
			out.print(name+"登陆成功,页面跳转........");
			response.sendRedirect("student/studentIndex.html");
		}
		else 
		{
			out.print("用户名或密码有误..");
			response.sendRedirect("index.jsp");
		}
	}
	if(s.equals("2"))
	{
		String sql="select * from teacher where tId='"+name+"' and tPass='"+pass+"'";
		stmt=conn.createStatement();
		rs=stmt.executeQuery(sql);
		if(rs.next()) 
		{
			loginNum="2";
			session.setAttribute("lnum",loginNum);
			session.setAttribute("name",name);
			out.print(name+"登陆成功,页面跳转........");
			response.sendRedirect("teacher/teacherIndex.html");
		}
		else 
		{
			out.print("用户名或密码有误..");
			response.sendRedirect("index.jsp");
		}
	}
	if(s.equals("3"))
	{
		String sql="select * from admin where aId='"+name+"' and aPass='"+pass+"'";
		stmt=conn.createStatement();
		rs=stmt.executeQuery(sql);
		if(rs.next()) 
		{
			loginNum="3";
			session.setAttribute("lnum",loginNum);
			session.setAttribute("name",name);
			out.print("管理员"+name+"登陆成功,页面跳转........");
			response.sendRedirect("admin/adminIndex.html");
		}
		else 
		{
			out.print("用户名或密码有误..");
			out.print("<a href=index.jsp>登陆页面</a>");
		}
	}
}
catch(Exception e){out.print(e);
//response.sendRedirect("index.jsp");
}
%>
</body>
</html>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?