系统一共分为1个角色分别是:员工
登录
- <%@ 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, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>登录title>
- <link rel="icon" href="<%=path%>/resource/static/favicon.ico">
- <link rel="stylesheet" href="<%=path%>/resource/static/bootstrap/css/bootstrap.min.css">
- <link rel="stylesheet" href="<%=path%>/resource/static/admin/css/login.css">
- <script src="<%=path%>/resource/static/js/vue.min.js">script>
- <script src="<%=path%>/resource/static/js/jquery-3.3.1.min.js">script>
- <script src="<%=path%>/resource/static/bootstrap/js/bootstrap.bundle.js">script>
- head>
- <body>
- <div class="login" style="height:430px;">
- <form id="saveForm">
- <h2>员工管理系统h2>
- <div class="form-group">
- <label>用户名label>
- <input type="text" v-model="username" name="username" id="username" class="form-control form-control-lg">
- div>
- <div class="form-group">
- <label>密码label>
- <input type="password" v-model="password" name ="password" id="password" class="form-control form-control-lg" id="pwd">
- div>
-
- <button type="button" :disabled="loading" @click="login" id="login" class="btn btn-primary btn-lg btn-block">
- <span v-show="loading" class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true">span>
- 立即登录
- button>
- <button type="button" id="register" class="btn btn-info btn-lg btn-block">
- <span v-show="loading" class="spinner-grow spinner-grow-sm" role="status" aria-hidden="true">span>
- 立即注册
- button>
-
- form>
- div>
-
- <script>
-
- $("#register").click(function(){
- window.parent.location.href="LoginServlet?action=toRegister";
- });
-
- $("#login").click(function(){
- var username = $("#username").val();
- var password = $("#password").val();
- if(username == null || username == ""){
- alert("请填写用户名");
- return false;
- }if(password == null || password == ""){
- alert("请填写密码");
- return false;
- }
- //执行添加的操作ajax
- $.ajax({
- cache:true,
- type:"post",
- url:"LoginServlet?action=login",
- data:$("#saveForm").serialize(),
- async:false,
- success:function(e){
- if(e == 'ok'){
- alert("登录成功");
- window.parent.location.href="LoginServlet?action=toMain";
- }else{
- alert("登录失败,账号或密码错误");
- }
- }
- })
- });
-
- script>
-
- body>
- html>
- /**
- * 登录
- * @param request
- * @param response
- * @throws ServletException
- * @throws IOException
- */
- public void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {//处理登录
- //清空登录记录
- request.getSession().invalidate();
- //进行登录操作
- String username = request.getParameter("username");
- String password = request.getParameter("password");
- Admin admin1 = loginService.selectAdmin(username,password);
- if(admin1 != null){
- response.getWriter().print("ok");
- request.getSession().setAttribute("admin",admin1);
- request.getSession().setAttribute("flag",1);
- }else{
- response.getWriter().print("error");
- }
-
- }