系统一共分为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 + "/";
- %>
- html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
- <title>公交线路查询系统title>
- <link href="resource/css/bootstrap.min.css" rel="stylesheet">
- <link href="resource/css/a3common.css" rel="stylesheet">
- <link rel="stylesheet" href="resource/css/login.css">
- <link rel="stylesheet" href="resource/css/font_43459_lbtux0zjkr6yldi.css">
- head>
-
-
-
- <div id="main" class="main-warp" style="height: 100%;">
- <div class="main-content">
- <div class="formDiv">
-
- <h2 class="text-center">登录h2>
-
-
- <form id="loginForm" method="post">
- <div class="dataform" >
- <div class="input-warp gap">
- <span class="input-icon iconfont icon-yonghu1">span>
- <input id="userName" name="userName" type="text" class="inputs" placeholder="手机号码或登录账号" maxlength="64">
- div>
-
- <span id="userNameErr" style="color:red" >${msg}span>
-
-
- <div class="input-warp gap">
- <span class="input-icon iconfont icon-baomi">span>
- <input class="inputs" type="password" name="password" placeholder="密码" id="password" maxlength="20">
- div>
-
- <div class=" gap">
- <span class="input-icon ">角色span>
- <select name="type" class="select">
- <option value="1">管理员option>
- <option value="2">司机option>
- <option value="3">乘客option>
- select>
-
- div>
-
-
-
- <div class="btn-warp gap" >
- <div class="text-center" >
-
- <button type="button" id="btnLogin" class="btn btn-block lgbtn blue">登录button>
- div>
- div>
-
- <div class="gap">
- <div class="pull-right" style="margin-top: -7px">
- |<a type="button" id ="addUser" class="link">新乘客注册a>div>
- <div class="pretty-box">
- div>
- div>
-
-
-
- div>
- form>
-
- div>
- div>
- div>
-
- <style>
- .copyrights{text-indent:-9999px;height:0;line-height:0;font-size:0;overflow:hidden;}
- style>
- <div class="copyrights" id="links20210126">
- Collect from <a href="http://www.cssmoban.com/" title="网站模板">模板之家a>
- <a href="https://www.chazidian.com/" title="查字典">查字典a>
- div>
- <script src="layui/jquery-1.9.1.min.js">script>
-
-
- <script src="resource/component/layui/layui.js">script>
- <script src="resource/component/pear/pear.js">script>
- <script>
- layui.use(['layer', 'form','jquery'], function(){
- var form = layui.form,
- layer = layui.layer,
- $= layui.jquery;
- form.render();//这句一定要加,占坑
-
-
- $('#addUser').on("click",function(e){
- layer.open({
- //调整弹框的大小
- area:['500px','800px'],
- shadeClose:true,//点击旁边地方自动关闭
- //动画
- anim:2,
- //弹出层的基本类型
- type: 2,
- title: '注册乘客',
- //刚才定义的弹窗页面
- content: 'UserServlet?action=toRegister', //这里content是一个URL,如果你不想让iframe出现滚动条,你还可以content: ['http://sentsin.com', 'no']
-
- });
- });
-
-
-
- $("#btnLogin").on("click", function() {
- var userName = $("#userName").val().trim(); // trim()去除空格
- var password = $("#password").val().trim();
- var type = $("#type").val();
-
-
- if(userName == ""){
- layer.msg('用户名或者手机号不能为空!');
- return false;
- }
- if(password == ""){
- layer.msg('密码不能为空!');
- return false;
- }
- if(type == ""){
- layer.msg('请选择角色!');
- 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("登录失败,账号或者密码错误!");
- }
- }
- })
-
- });
-
- setTimeout(function(){ $("#userNameErr").html("")},3000);
- });
- 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")){//司机
- Driver driver = driverService.selectDriver(userName,password);
- if (driver != null) {
- message = "yes";
- request.getSession().setAttribute("flag",2);
- request.getSession().setAttribute("driver",driver);
- }
- }else if(type != null && type.equals("3")){//乘客
- User user = userService.selectUser(userName,password);
- if (user != null) {
- message = "yes";
- request.getSession().setAttribute("flag",3);
- request.getSession().setAttribute("user",user);
- }
- }
- response.getWriter().print(message);
- }