系统一共分为5个角色分别是:管理员,用户(员工,财务,部门经理,老板)
- <%@ 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">
- <form id="saveForm">
- <h2>OA管理系统登录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>
- <div class="form-group form-check">
- <input type="radio" class="form-check-input" name="type" value="1" id="exampleCheck2" checked>
- <label class="form-check-label" for="exampleCheck2">管理员label>
- <input type="radio" class="form-check-input" name="type" value="2" id="exampleCheck1" >
- <label class="form-check-label" for="exampleCheck1">普通用户label>
-
- 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>
- form>
- div>
-
- <script>
- $("#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:"login",
- data:$("#saveForm").serialize(),
- async:false,
- success:function(e){
- if(e){
- alert("登录成功");
- window.parent.location.href="toMain";
- }else{
- alert("登录失败,账号或密码错误");
- }
- }
- })
- });
-
- script>
-
- body>
- html>
- /**
- * 登录
- * @param username
- * @param request
- * @param password
- * @param session
- * @param response
- * @param mv
- * @return
- * @throws ServletException
- * @throws IOException
- */
- @RequestMapping("/login")
- @ResponseBody
- public boolean login(@RequestParam("username")String username,
- HttpServletRequest request,@RequestParam("password")String password,
- HttpSession session,HttpServletResponse response,ModelAndView mv) throws ServletException, IOException {
- session.removeAttribute("admin");
- session.removeAttribute("user");
- String type=request.getParameter("type").toString();
- User user =new User();
- Admin admin = new Admin();
- request.getSession().setAttribute("type", type);
- boolean re = false;
- if(type != null && type.equals("1")){
- admin.setUsername(username);
- admin.setPassword(password);
- Admin admin1 = us.selectAdmin(admin);
- if(admin1 != null){
- request.getSession().setAttribute("admin", admin1);
- session.setAttribute("admin", admin1);
- re = true;
- }
- }else if(type != null && type.equals("2")){
- user.setUsername(username);
- user.setPassword(password);
- User te = us.selectUser(user);
- if(te != null){
- request.getSession().setAttribute("user", te);
- session.setAttribute("user", te);
- re = true;
- }
- }
- return re;
-
- }