这是我的Jsp期末作业,用jsp写一个简单的用户管理系统
下面是登录界面,Login用了几个css就不贴上来了
LoginCheck是用来验证用户名和密码是否正确
我的数据库用的是mysql,名字是db_01,账号和密码都是root
1.Login.jsp
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<title>管理系统登录界面</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<!-- CSS -->
<link rel='stylesheet' href='http://fonts.googleapis.com/css?family=PT+Sans:400,700'>
<link rel="stylesheet" href="assets/css/reset.css">
<link rel="stylesheet" href="assets/css/supersized.css">
<link rel="stylesheet" href="assets/css/style.css">
<!-- HTML5 shim, for IE6-8 support of HTML5 elements -->
<!--[if lt IE 9]>
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
</head>
<body>
<div class="page-container">
<h1>Login</h1>
<form action="loginCh.jsp" method="post">
<input type="text" name="name" class="username" placeholder="Username">
<input type="password" name="pwd" class="password" placeholder="Password">
<button type="submit">点击登录</button>
<div class="error"><span>+</span></div>
</form>
</div>
<!-- Javascript -->
<script src="assets/js/jquery-1.8.2.min.js"></script>
<script src="assets/js/supersized.3.2.7.min.js"></script>
<script src="assets/js/supersized-init.js"></script>
<script src="assets/js/scripts.js"></script>
</body>
</html>
2.LoginCheck
<%@ page language="java" import="java.util.*,java.sql.*" pageEncoding="utf-8"%>
<body>
<%
String name=new String(request.getParameter("name").getBytes("ISO8859_1"),"UTF-8");
String pwd=new String(request.getParameter("pwd").getBytes("ISO8859_1"),"UTF-8");
// 加载数据库驱动,注册到驱动管理器
Class.forName("com.mysql.jdbc.Driver");
// 数据库连接字符串
String url = "jdbc:mysql://localhost:3306/db_01";
// 数据库用户名
String usename = "root";
// 数据库密码
String psw = "root";
// 创建Connection连接
Connection conn = DriverManager.getConnection(url,usename,psw);
// 判断 数据库连接是否为空
if(conn != null){
String sql="select * from user where usr='"+name+"' and passwd='"+ pwd + "'";
Statement stmt = conn.createStatement();
ResultSet rs=stmt.executeQuery(sql);
if(rs.next()){
response.sendRedirect("success.jsp");
}else{
out.print("用户名或密码错误,请重新输入!");
%>
<a href="index.jsp">返回</a>
<%
}
// 输出连接信息
//out.println("数据库连接成功!");
// 关闭数据库连接
conn.close();
}else{
// 输出连接信息
out.println("数据库连接失败!");
}
%>
<% session.putValue("name",name);%>
</body>
登录界面代码就这么多,后续还有注册、管理、查询等界面
查看后续代码请看这里👉后续代码