系统一共分为3个角色分别是:管理员,用户,巡更点
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="resource/login/bootstrap.min.css">
<!-- Loding font -->
<link href="https://fonts.googleapis.com/css?family=Montserrat:300,700" rel="stylesheet">
<!-- Custom Styles -->
<link rel="stylesheet" type="text/css" href="resource/login/styles.css">
<title>巡更管理系统</title>
</head>
<body>
<!-- Backgrounds -->
<div id="login-bg" class="container-fluid">
<div class="bg-img"></div>
<div class="bg-color"></div>
</div>
<!-- End Backgrounds -->
<div class="container" >
<div class="row justify-content-center">
<div class="col-lg-8">
<div class="login" style="margin-top:200px;">
<h1>巡更管理系统登录</h1>
<!-- Loging form -->
<form id="loginForm" >
<div class="form-group">
<input type="email" class="form-control" id="userName" name="userName" placeholder="手机号码或登录账号">
</div>
<div class="form-group">
<input type="password" class="form-control" name="password" id="password" placeholder="请输入密码">
</div>
<div class="form-check">
<!-- <label class="switch">
<input type="checkbox">
<span class="slider round"></span>
</label> -->
<select name="type" id="type" class="form-control">
<option value="1">管理员</option>
<option value="2">用户</option>
<option value="3">巡更点</option>
</select>
<!-- <label class="form-check-label" for="exampleCheck1">Remember me</label>
<label class="forgot-password"><a href="#">Forgot Password?<a></label> -->
</div>
<br>
<button type="button" id="login" class="btn btn-lg btn-block btn-success">登录</button>
</form>
<!-- End Loging form -->
</div>Copyright © 2022.Company name All rights reserved.
</div>
</div>
</div>
<script src="layui/jquery-1.9.1.min.js"></script>
<script src="layui/layui.js"></script>
<script>
$("#login").on("click", function() {
var userName = $("#userName").val().trim(); // trim()去除空格
var password = $("#password").val().trim();
var type = $("#type").val();
if(userName == ""){
alert('用户名或者手机号不能为空!');
return false;
}
if(password == ""){
alert('密码不能为空!');
return false;
}
if(type == ""){
alert('请选择角色!');
return false;
}
$.ajax({
cache : true,
type : "post",
url : "LoginServlet?action=login",
data : $("#loginForm").serialize(),
async : false,
success : function(e) {
if (e == 'yes') {
alert("登录成功!");
window.parent.location.href = "LoginServlet?action=toMain";
}else {
alert("登录失败,账号或者密码错误!");
}
}
})
});
</script>
</body>
</html>
protected void login(HttpServletRequest request, HttpServletResponse response) throws Exception {//跳转到添加用户界�?
String userName = request.getParameter("userName");
String password = request.getParameter("password");
String type = request.getParameter("type");
String message = "no";
if(type != null && type.equals("1")){//admin
Admin admin = service.selectAdmin(userName,password);
if (admin != null) {
message = "yes";
request.getSession().setAttribute("flag",1);
request.getSession().setAttribute("admin",admin);
}
}else if(type != null && type.equals("2")){
User user = service.seletUser(userName,password);
if (user != null) {
message = "yes";
request.getSession().setAttribute("flag",2);
request.getSession().setAttribute("user",user);
}
}else if(type != null && type.equals("3")){
Point point = service.selectPoint(userName,password);
if (point != null) {
message = "yes";
request.getSession().setAttribute("flag",3);
request.getSession().setAttribute("point",point);
}
}
response.getWriter().print(message);
}