作者微信 bishe2022

代码功能演示视频在页面下方,请先观看;如需定制开发,联系页面右侧客服

Web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">

  <display-name>DormManage</display-name>

  <welcome-file-list>

    <welcome-file>login.jsp</welcome-file>

  </welcome-file-list>

  

  <filter>

  <filter-name>loginFilter</filter-name>

  <filter-class>com.lero.filter.LoginFilter</filter-class>

  </filter>

  

  <filter-mapping>

  <filter-name>loginFilter</filter-name>

  <url-pattern>/*</url-pattern>

  </filter-mapping>

  

  <servlet>

  <servlet-name>loginServlet</servlet-name>

  <servlet-class>com.lero.web.LoginServlet</servlet-class>

  </servlet>

  

  <servlet-mapping>

  <servlet-name>loginServlet</servlet-name>

  <url-pattern>/login</url-pattern>

  </servlet-mapping>

  

   <servlet>

  <servlet-name>blankServlet</servlet-name>

  <servlet-class>com.lero.web.BlankServlet</servlet-class>

  </servlet>

  

  <servlet-mapping>

  <servlet-name>blankServlet</servlet-name>

  <url-pattern>/blank</url-pattern>

  </servlet-mapping>

  

  <servlet>

  <servlet-name>dormBuildServlet</servlet-name>

  <servlet-class>com.lero.web.DormBuildServlet</servlet-class>

  </servlet>

  

  <servlet-mapping>

  <servlet-name>dormBuildServlet</servlet-name>

  <url-pattern>/dormBuild</url-pattern>

  </servlet-mapping>

  

   <servlet>

  <servlet-name>dormManagerServlet</servlet-name>

  <servlet-class>com.lero.web.DormManagerServlet</servlet-class>

  </servlet>

  

  <servlet-mapping>

  <servlet-name>dormManagerServlet</servlet-name>

  <url-pattern>/dormManager</url-pattern>

  </servlet-mapping>

  

   <servlet>

  <servlet-name>studentServlet</servlet-name>

  <servlet-class>com.lero.web.StudentServlet</servlet-class>

  </servlet>

  

  <servlet-mapping>

  <servlet-name>studentServlet</servlet-name>

  <url-pattern>/student</url-pattern>

  </servlet-mapping>

  

  <servlet>

  <servlet-name>recordServlet</servlet-name>

  <servlet-class>com.lero.web.RecordServlet</servlet-class>

  </servlet>

  

  <servlet-mapping>

  <servlet-name>recordServlet</servlet-name>

  <url-pattern>/record</url-pattern>

  </servlet-mapping>

  

   <servlet>

  <servlet-name>passwordServlet</servlet-name>

  <servlet-class>com.lero.web.PasswordServlet</servlet-class>

  </servlet>

  

  <servlet-mapping>

  <servlet-name>passwordServlet</servlet-name>

  <url-pattern>/password</url-pattern>

  </servlet-mapping>

</web-app>






login.jsp

<%@ page language="java" contentType="text/html; charset=utf-8"

    pageEncoding="utf-8"%>

<%@ page import="com.lero.model.Admin" %>

<%@ page import="com.lero.model.DormManager" %>

<%@ page import="com.lero.model.Student" %>

<%

if(request.getAttribute("user")==null){

String userName=null;

String password=null;

String userType=null;

String remember=null;


Cookie[] cookies=request.getCookies();

for(int i=0;cookies!=null && i<cookies.length;i++){

if(cookies[i].getName().equals("dormuser")){

userName=cookies[i].getValue().split("-")[0];

password=cookies[i].getValue().split("-")[1];

userType=cookies[i].getValue().split("-")[2];

remember=cookies[i].getValue().split("-")[3];

}

}


if(userName==null){

userName="";

}


if(password==null){

password="";

}


if(userType==null){

userType="";

} else if("admin".equals(userType)){

pageContext.setAttribute("user", new Admin(userName,password));

pageContext.setAttribute("userType", 1);

} else if("dormManager".equals(userType)) {

pageContext.setAttribute("user", new DormManager(userName,password));

pageContext.setAttribute("userType", 2);

} else if("student".equals(userType)) {

pageContext.setAttribute("user", new Student(userName,password));

pageContext.setAttribute("userType", 3);

}


if("yes".equals(remember)) {

pageContext.setAttribute("remember", 1);

}


}

%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>宿舍管理系统登录</title>

<link href="${pageContext.request.contextPath}/bootstrap/css/bootstrap.css" rel="stylesheet">

<link href="${pageContext.request.contextPath}/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">

<script src="${pageContext.request.contextPath}/bootstrap/js/jQuery.js"></script>

<script src="${pageContext.request.contextPath}/bootstrap/js/bootstrap.js"></script>

<script type="text/javascript">

function checkForm() {

var userName = document.getElementById("userName").value;

var password = document.getElementById("password").value;

var userTypes = document.getElementsByName("userType");

var userType = null;

for(var i=0;i<userTypes.length;i++) {

if(userTypes[i].checked) {

userType=userTypes[i].value;

break;

}

}

if (userName == null || userName == "") {

document.getElementById("error").innerHTML = "用户名不能为空";

return false;

}

if (password == null || password == "") {

document.getElementById("error").innerHTML = "密码不能为空";

return false;

}

if (userType == null || userType == "") {

document.getElementById("error").innerHTML = "请选择用户类型";

return false;

}

return true;

}

</script>


<style type="text/css">

  body {

        padding-top: 200px;

        padding-bottom: 40px;

        background-image: url('images/bg.jpg');

        background-position: center;

background-repeat: no-repeat;

background-attachment: fixed;

      }

      

      .radio {

       padding-top: 10px;

        padding-bottom:10px;

      }

      

      .form-signin-heading{

       text-align: center;

      }


      .form-signin {

        max-width: 300px;

        padding: 19px 29px 0px;

        margin: 0 auto 20px;

        background-color: #fff;

        border: 1px solid #e5e5e5;

        -webkit-border-radius: 5px;

           -moz-border-radius: 5px;

                border-radius: 5px;

        -webkit-box-shadow: 0 1px 2px rgba(0,0,0,.05);

           -moz-box-shadow: 0 1px 2px rgba(0,0,0,.05);

                box-shadow: 0 1px 2px rgba(0,0,0,.05);

      }

      .form-signin .form-signin-heading,

      .form-signin .checkbox {

        margin-bottom: 10px;

      }

      .form-signin input[type="text"],

      .form-signin input[type="password"] {

        font-size: 16px;

        height: auto;

        margin-bottom: 15px;

        padding: 7px 9px;

      }

</style>


</head>

<body>

<div>

      <form name="myForm" action="login" method="post" onsubmit="return checkForm()">

        <h2><font color="gray">宿舍管理系统</font></h2>

        <input id="userName" name="userName" value="${user.userName }" type="text" placeholder="用户名...">

        <input id="password" name="password" value="${user.password }" type="password" placeholder="密码..." >

        <label class="radio inline">

          <input id="admin" type="radio" name="userType" value="admin"  checked/> 系统管理员

</label>

<label class="radio inline">

<input id="dormManager" type="radio" name="userType" value="dormManager" ${userType==2?'checked':''} /> 宿舍管理员

</label>

<label class="radio inline">

<input id="student" type="radio" name="userType" value="student"  ${userType==3?'checked':''}/> 学生

</label>

        <label>

          <input id="remember" name="remember" type="checkbox" value="remember-me" ${remember==1?'checked':''}>记住我 &nbsp;&nbsp;&nbsp;&nbsp; <font id="error" color="red">${error }</font>  

        </label>

        <button class="btn btn-large btn-primary" type="submit">登录</button>

        &nbsp;&nbsp;&nbsp;&nbsp;

        <button class="btn btn-large btn-primary" type="button" >重置</button>


<p style="padding-top: 15px;">版权所有  2014  Lero  <a href="http://www.lero.com" target="_blank">http://www.lero.com</a></p>

      </form>

</div>

</body>

</html>



Home