SpringMVC用例篇之用戶登錄系統詳細開發流程

来源:https://www.cnblogs.com/wxhblog/archive/2018/02/11/8442706.html
-Advertisement-
Play Games

SpringMVC入門項目,用戶登錄系統,詳細記錄了SpringMVC的開發流程! ...


一.用戶登錄系統環境配置:

1.1:開發環境:

Windows7(x86_64);Eclipse Java EE IDE for Web Developers.Version: Oxygen.1a Release (4.7.1a); java version "1.8.0_73"

1.2:開發框架:

spring-framework-5.0.3.RELEASE   DButils

1.3:所需jar包截圖:

二.資料庫的設計:

三.開發流程:

 1.1.配置web.xml文件

 1 <!-- 註冊SpringMVC的前端控制器DispatchcerServlet -->
 2   <servlet>
 3           <servlet-name>DispatchcerServletSpringMVC</servlet-name>
 4           <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
 5           <!-- 初始化SpringMVC容器 -->
 6           <init-param>
 7                   <param-name>contextConfigLocation</param-name>
 8                   <param-value>classpath:SpringMVC.xml</param-value>
 9           </init-param>
10   </servlet>
11   <!-- 攔截 以.action結尾的請求-->
12   <servlet-mapping>
13           <servlet-name>DispatchcerServletSpringMVC</servlet-name>
14           <url-pattern>*.action</url-pattern>
15   </servlet-mapping>

1.2.配置SpringMVC.xml文件

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4     xmlns:context="http://www.springframework.org/schema/context"
 5     xmlns:mvc="http://www.springframework.org/schema/mvc"
 6     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 7         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
 8         http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
 9     <!-- 指定使用註解方式配置 -->
10     <!-- 掃描以下包及其子包內容 --> 
11     <mvc:annotation-driven></mvc:annotation-driven>
12     <context:component-scan base-package="com.login.handler"></context:component-scan>
13     <!-- 不處理靜態內容 -->
14     <mvc:default-servlet-handler/>
15     <!--配置視圖解析器-->
16     <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
17          <!-- 首碼 -->
18         <property name="prefix" value="/WEB-INF/admin/" />
19         <!-- 尾碼 -->
20         <property name="suffix" value=".jsp" />
21     </bean>
22 </beans>

1.3.C3P0資料庫連接池的配置:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <c3p0-config>
 3   <named-config name="hello"> 
 4       <property name="driverClass">com.mysql.jdbc.Driver</property>
 5       <property name="jdbcUrl">jdbc:mysql://localhost:3306/springmvc</property>
 6       <property name="user">root</property>
 7       <property name="password">root</property>
 8     <property name="initialPoolSize">2</property>
 9     <property name="maxPoolSize">5</property>
10   </named-config>
11 </c3p0-config>

1.4.視圖層目錄結構:

1.5.各層關鍵代碼展示:

  <1>.view層:

   @1.login.jsp頁面:

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <link rel="stylesheet" href="<%=request.getContextPath() %>/css/bootstrap.css" />
 8 <style type="text/css">
 9     .div_login {
10         width: 360px;
11         height: auto;
12         margin-top: 1%;
13         background-color:white;
14         
15     }
16 </style>
17 <title>Admin Login</title>
18 </head>
19 <body style="background-color:cadetblue">
20 <!--
21     作者:[email protected]
22     時間:2018-02-07
23     描述:
24 -->
25     <div class="container-fluid">
26         <div class="row" style="margin-top: 8%;">
27             <center><font color="red" size="5px">${error_msg }</font></center>
28             <center><h2>AdminLogin</h2></center>
29         </div>
30         <div class="row">
31             <center>
32                 <div class="div_login">
33                     <div class="row"><center><p style="margin-top: 10px;">請登錄開啟你的會話旅程</p></center></div>
34                     <div class="row">
35                             <form action="<%=request.getContextPath() %>/admin/adminCheck.action" method="post">
36                                   <div class="form-group">
37                                     <input type="text" name="name"  class="form-control" id="name" placeholder="姓名" style="width: 350px;">
38                                   </div>
39                                   <div class="form-group">
40                                     <input type="password" name="passwd" class="form-control" id="passwd" placeholder="密碼" style="width: 350px;">
41                                   </div>
42                                   <div>
43                                       <div class="col-lg-5 col-md-5 checkbox">
44                                           <label><input type="checkbox" name="remember">記住登錄信息</label>
45                                       </div>
46                                       <div class="col-lg-4 col-lg-offset-3 col-md-4 col-md-offset-3"><button type="submit" class="btn btn-primary">登錄</button></div>
47                                   </div>
48                             </form>
49                     </div>
50                     <div class="row"><div class="col-lg-5 col-md-5"><a href="<%=request.getContextPath() %>/register.jsp">註冊一個新賬戶</a></div></div>
51                 </div>
52             </center>
53         </div>
54     </div>
55 <!-- 消息彈出框提示 -->
56 <script type="text/javascript">
57     var msg = "${off_msg}" 
58     if (msg != "") {
59         alert("${off_msg}" );    
60     }
61 </script>
62 </body>
63 </html>

   @2.register.jsp頁面:

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 4 <html>
 5 <head>
 6 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 7 <link rel="stylesheet" href="<%=request.getContextPath() %>/css/bootstrap.css" />
 8 <style type="text/css">
 9     .div_login {
10         width: 360px;
11         height: auto;
12         margin-top: 1%;
13         background-color:white;
14         
15     }
16 </style>
17 <title>Register Admin</title>
18 </head>
19 <body style="background-color:cadetblue">
20         <div class="container-fluid">
21             <div class="row" style="margin-top: 8%;">
22             <center><font color="white" size="5px">${msg }</font></center>
23             <center><h2>RegisterAdmin</h2></center>
24         </div>
25         <div class="row">
26             <center>
27                 <div class="div_login">
28                     <div class="row"><center><p style="margin-top: 10px;">註冊一個新賬戶</p></center></div>
29                     <div class="row">
30                             <form action="<%=request.getContextPath() %>/admin/adminAdd.action" method="post">
31                                  <div class="form-group">
32                                     <input type="text" name="account" class="form-control" id="account" placeholder="賬號" style="width: 350px;">
33                                   </div>
34                                   <div class="form-group">
35                                     <input type="text" name="name"  class="form-control" id="name" placeholder="姓名" style="width: 350px;">
36                                   </div>
37                                   <div class="form-group">
38                                     <input type="password" name="passwd" class="form-control" id="passwd" placeholder="密碼" style="width: 350px;">
39                                   </div>
40                                    <div class="form-group">
41                                     <input type="password" name="passwd_ref" class="form-control" id="passwd_ref" placeholder="確認密碼" style="width: 350px;">
42                                   </div>
43                                    <div class="form-group">
44                                     <input type="email" name="email" class="form-control" id="email" placeholder="郵箱" style="width: 350px;">
45                                   </div>
46                                   <div>
47                                       <div class="col-lg-5 col-md-5 checkbox">
48                                           <label><input type="checkbox" name="remember">同意註冊<a href="#">條約</a></label>
49                                       </div>
50                                       <div class="col-lg-4 col-lg-offset-3 col-md-4 col-md-offset-3"><button type="submit" class="btn btn-primary">註冊</button></div>
51                                   </div>
52                             </form>
53                     </div>
54                     <div class="row"><div class="col-lg-3 col-md-3"><a href="<%=request.getContextPath() %>/login.jsp">登錄賬號</a></div></div>
55                 </div>
56             </center>
57         </div>
58         </div>
59 </body>
60 </html>

   @3.adminWelcome.jsp頁面:

  1 <%@ page language="java" contentType="text/html; charset=UTF-8"
  2     pageEncoding="UTF-8"%>
  3     <%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core"%>
  4 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  5 <html>
  6 <head>
  7 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  8 <link rel="stylesheet" href="<%=request.getContextPath() %>/css/bootstrap.css" />
  9 <style type="text/css">
 10     .style_display{
 11         width: 360px;
 12         display: none;
 13     }
 14     .style_display2{
 15         width: 360px;
 16     }
 17 </style>
 18 <script type="text/javascript">
 19     function $(id){
 20         return document.getElementById(id);
 21     }
 22     function alterAdmin(){
 23         var display_element = $("AdminInfo");
 24         display_element.setAttribute("class","style_display2");
 25     }
 26     function deleteAdmin(){
 27         window.location.href="<%=request.getContextPath() %>/admin/adminDelete.action";
 28     }
 29     function adminLogout(){
 30         window.location.href="<%=request.getContextPath() %>/admin/adminLogout.action";
 31     }
 32     function showPicture(){
 33         window.location.href="<%=request.getContextPath() %>/image/showImage.action";
 34     }
 35 </script>
 36 <title>AdminWelcome</title>
 37 </head>
 38 <body>
 39 <!-- 消息彈出框提示 -->
 40 <script type="text/javascript">
 41     var msg = "${error_msg}" 
 42     if (msg != "") {
 43         alert("
              
您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 記憶體限制:256 MiB時間限制:1000 ms標準輸入輸出 題目類型:傳統評測方式:文本比較 上傳者: 匿名 記憶體限制:256 MiB時間限制:1000 ms標準輸入輸出 題目類型:傳統評測方式:文本比較 上傳者: 匿名 提交提交記錄統計討論測試數據 題目描述 這是一道模板題。 輸入兩個多項式,輸 ...
  • Description 在組合博弈論中,Nim游戲是一個非常經典的問題,Nim游戲可描述如下:有n堆石子,每堆石子數分別為a1, a2, …, an (ai≥0)。現有兩人輪流從這n堆中取石子,每次必須從某一堆中取任意多的石子,至少要取一個,必須從同一堆中取石子,並且不能超過這一堆石子的總數。如果某 ...
  • 聯編的概念 聯編是指一個電腦程式自身彼此關聯的過程,在這個聯編過程中,需要確定程式中的操作調用(函數調用)與執行該操作(函數)的代碼段之間的映射關係。 意思就是這個函數的實現有多種,聯編就是把調用和對應的實現進行映射的操作。按照聯編進行的階段不同,可分為靜態聯編和動態聯編。 靜態聯編 靜態聯編工作 ...
  • 前言 當前大多數app都有查找附近的功能, 簡單的有查找周圍的運動場館, 複雜的有滴滴, 摩拜查找周圍的車輛. 本文主要闡述查找附近地點的一般實現. 搜索附近的人也是同樣的思路. 方案比較 方案1 (性能還不錯) 資料庫直接存經緯度, 然後計算矩形邊界值, 走索引查詢 方案2 (還沒試過) 將經緯度 ...
  • python字元串格式化兩種方式:百分號方式、format方式 用百分號字元串拼接 列印浮點數: 列印百分比: format ...
  • 本文主要介紹Hibernate主鍵的生成策略、持久化類的編寫規則、 持久化對象的三種狀態、hibernate的緩存、Hibernate的事務。 ...
  • 1 學習計劃 1、jQuery easyUI中動態添加選項卡 2、jquery ztree插件使用 n 下載ztree n 基於標準json數據構造ztree n 基於簡單json數據構造ztree(重點) 3、資料庫建模工具PowerDesigner使用方式 4、myeclipse翻轉引擎插件使用 ...
  • 本人現在對zookeeper的環境搭建做一個總結,一般zookeeper的安裝部署可以有三種模式,單機模式、偽分散式和分散式,這三種模式在什麼時候應用具體看大家的使用場景,如果你只有一臺機器且只是想自己開發測試時用,你可以安裝個單機模式,簡單又實用。如果想裝逼但又沒有足夠的機器,那你可以選擇偽分散式 ...
一周排行
    -Advertisement-
    Play Games
  • 移動開發(一):使用.NET MAUI開發第一個安卓APP 對於工作多年的C#程式員來說,近來想嘗試開發一款安卓APP,考慮了很久最終選擇使用.NET MAUI這個微軟官方的框架來嘗試體驗開發安卓APP,畢竟是使用Visual Studio開發工具,使用起來也比較的順手,結合微軟官方的教程進行了安卓 ...
  • 前言 QuestPDF 是一個開源 .NET 庫,用於生成 PDF 文檔。使用了C# Fluent API方式可簡化開發、減少錯誤並提高工作效率。利用它可以輕鬆生成 PDF 報告、發票、導出文件等。 項目介紹 QuestPDF 是一個革命性的開源 .NET 庫,它徹底改變了我們生成 PDF 文檔的方 ...
  • 項目地址 項目後端地址: https://github.com/ZyPLJ/ZYTteeHole 項目前端頁面地址: ZyPLJ/TreeHoleVue (github.com) https://github.com/ZyPLJ/TreeHoleVue 目前項目測試訪問地址: http://tree ...
  • 話不多說,直接開乾 一.下載 1.官方鏈接下載: https://www.microsoft.com/zh-cn/sql-server/sql-server-downloads 2.在下載目錄中找到下麵這個小的安裝包 SQL2022-SSEI-Dev.exe,運行開始下載SQL server; 二. ...
  • 前言 隨著物聯網(IoT)技術的迅猛發展,MQTT(消息隊列遙測傳輸)協議憑藉其輕量級和高效性,已成為眾多物聯網應用的首選通信標準。 MQTTnet 作為一個高性能的 .NET 開源庫,為 .NET 平臺上的 MQTT 客戶端與伺服器開發提供了強大的支持。 本文將全面介紹 MQTTnet 的核心功能 ...
  • Serilog支持多種接收器用於日誌存儲,增強器用於添加屬性,LogContext管理動態屬性,支持多種輸出格式包括純文本、JSON及ExpressionTemplate。還提供了自定義格式化選項,適用於不同需求。 ...
  • 目錄簡介獲取 HTML 文檔解析 HTML 文檔測試參考文章 簡介 動態內容網站使用 JavaScript 腳本動態檢索和渲染數據,爬取信息時需要模擬瀏覽器行為,否則獲取到的源碼基本是空的。 本文使用的爬取步驟如下: 使用 Selenium 獲取渲染後的 HTML 文檔 使用 HtmlAgility ...
  • 1.前言 什麼是熱更新 游戲或者軟體更新時,無需重新下載客戶端進行安裝,而是在應用程式啟動的情況下,在內部進行資源或者代碼更新 Unity目前常用熱更新解決方案 HybridCLR,Xlua,ILRuntime等 Unity目前常用資源管理解決方案 AssetBundles,Addressable, ...
  • 本文章主要是在C# ASP.NET Core Web API框架實現向手機發送驗證碼簡訊功能。這裡我選擇是一個互億無線簡訊驗證碼平臺,其實像阿裡雲,騰訊雲上面也可以。 首先我們先去 互億無線 https://www.ihuyi.com/api/sms.html 去註冊一個賬號 註冊完成賬號後,它會送 ...
  • 通過以下方式可以高效,並保證數據同步的可靠性 1.API設計 使用RESTful設計,確保API端點明確,並使用適當的HTTP方法(如POST用於創建,PUT用於更新)。 設計清晰的請求和響應模型,以確保客戶端能夠理解預期格式。 2.數據驗證 在伺服器端進行嚴格的數據驗證,確保接收到的數據符合預期格 ...