1. 程式人生 > 其它 >基於javaEE的簡單教務系統實現(一)

基於javaEE的簡單教務系統實現(一)

完成javaEE課程程式碼

首先登陸介面等

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!-- 引入bootstrap -->
    <link rel
="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.min.css"> <!-- 引入JQuery bootstrap.js--> <script src="${pageContext.request.contextPath}/js/jquery-3.2.1.min.js"></script> <script src="${pageContext.request.contextPath}/js/bootstrap.min.js"
></script> <style type="text/css"> body{ margin:0px; background: url('${pageContext.request.contextPath}/images/a.jpg') no-repeat; background-size:100% 100%; background-attachment:fixed; } #login-box { /*border:1px solid #F00;*/ padding: 35px; border-radius
:15px; background: #56666B; color: #fff; } </style> </head> <body> <div class="container" id="top"> <div class="row" style="margin-top: 280px; "> <div class="col-md-4"></div> <div class="col-md-4" id="login-box"> <form class="form-horizontal" role="form" action="${pageContext.request.contextPath}/login" id="from1" method="post"> <div class="form-group"> <label for="firstname" class="col-sm-3 control-label">使用者id</label> <div class="col-sm-9"> <input type="text" class="form-control" id="userID" placeholder="請輸入名字" name="username"> </div> </div> <div class="form-group"> <label for="lastname" class="col-sm-3 control-label">密碼</label> <div class="col-sm-9"> <input type="password" class="form-control" id="password" placeholder="請輸入密碼" name="password"> </div> </div> <%--<div class="form-group">--%> <%--<div class="col-sm-offset-2 col-sm-10">--%> <%--<div class="checkbox">--%> <%--<label class="checkbox-inline">--%> <%--<input type="radio" name="role" value="1" checked>管理員--%> <%--</label>--%> <%--<label class="checkbox-inline">--%> <%--<input type="radio" name="role" value="2">老師--%> <%--</label>--%> <%--<label class="checkbox-inline">--%> <%--<input type="radio" name="role" value="3">學生--%> <%--</label>--%> <%--</div>--%> <%--</div>--%> <%--</div>--%> <div class="form-group pull-right" style="margin-right: 15px;"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default btn-info">登入</button> </div> </div> </form> </div> <div class="col-md-4"></div> </div> </div> </body> </html>

實現可選擇的登入角色或者後臺識別登入角色等

介面效果

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

  <!--載入spring容器-->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/classes/spring/applicationContext-*.xml</param-value>
  </context-param>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <!--springMVC前端控制器載入-->
  <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <!--contextConfigLocation配置SpringMVC載入的配置檔案(配置處理器,對映器等等)
    如果不配置contextConfigLocation,預設載入的是:/WEB-INF/servlet名稱-servlet.xml(springmvc-servlet.xml)
    -->
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring/springmvc.xml</param-value>
    </init-param>
  </servlet>

  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>


  <!--spring為我們提供的亂碼過濾器-->
  <filter>
    <filter-name>CharacterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>utf-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!-- name要和 applicationContext.xml中的對應的bean的id一致 -->
  <!--Shiro攔截器 shiro入口-->
  <filter>
    <filter-name>shiroFilter</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    <init-param>
      <param-name>targetFilterLifecycle</param-name>
      <param-value>true</param-value>
    </init-param>
  </filter>

  <filter-mapping>
    <filter-name>shiroFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>


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

</web-app>