系统一共分为2个角色分别是:管理员,用户
- <%@ 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 lang="en">
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
-
- <link rel="stylesheet" href="resource/login/bootstrap.min.css">
-
- <link href="https://fonts.googleapis.com/css?family=Montserrat:300,700" rel="stylesheet">
-
- <link rel="stylesheet" type="text/css" href="resource/login/styles.css">
-
- <title>酒店预订系统title>
- head>
- <body>
-
-
- <div id="login-bg" class="container-fluid">
-
- <div class="bg-img">div>
- <div class="bg-color">div>
- div>
-
-
- <div class="container" >
- <div class="row justify-content-center">
- <div class="col-lg-8">
- <div class="login" style="margin-top:200px;">
-
- <h1>酒店预订系统登录h1>
-
-
- <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">
-
-
- <select name="type" id="type" class="form-control">
- <option value="1">管理员option>
- <option value="2">客户option>
- select>
-
-
- div>
-
- <br>
- <button type="button" id="login" class="btn btn-lg btn-block btn-success">登录button>
- 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 if(e == 'index') {
- alert("登录成功!");
- window.parent.location.href = "IndexServlet?action=toIndex";
- }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 = userService.selectUser(userName,password);
- if (user != null) {
- message = "index";
- request.getSession().setAttribute("flag",2);
- request.getSession().setAttribute("user",user);
- }
-
- }
- response.getWriter().print(message);
- }