1. 程式人生 > >Spring MVC 表單控制器實現驗證使用者登入驗證

Spring MVC 表單控制器實現驗證使用者登入驗證

轉自:http://blog.csdn.net/happyunbound/article/details/8236106

web.xml:

  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <web-appversion="2.4"xmlns="http://java.sun.com/xml/ns/j2ee"
  3.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4.     xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee   
  5.     http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
  6.     <servlet>
  7.         <!-- 定義Servlet名稱 -->
  8.         <servlet-name>dispatcherServlet</servlet-name>
  9.         <!-- Servlet具體實現類 -->
  10.         <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  11.         <!-- 初始化上下文物件 -->
  12.         <
    init-param>
  13.             <!-- 引數名稱 -->
  14.             <param-name>contextConfigLocation</param-name>
  15.             <!-- 載入配置檔案 -->
  16.             <param-value>/WEB-INF/applicationContext.xml</param-value>
  17.         </init-param>
  18.         <!-- 設定啟動的優先順序 -->
  19.         <
    load-on-startup>1</load-on-startup>
  20.     </servlet>
  21.     <!-- 採用萬用字元對映所有以html型別的請求 -->
  22.     <servlet-mapping>
  23.         <servlet-name>dispatcherServlet</servlet-name>
  24.         <url-pattern>*.html</url-pattern>
  25.     </servlet-mapping>
  26.     <welcome-file-list>
  27.         <welcome-file>index.jsp</welcome-file>
  28.     </welcome-file-list>
  29. </web-app>

applicationContext.xml:

  1. <?xmlversion="1.0"encoding="UTF-8"?>
  2. <beans
  3.     xmlns="http://www.springframework.org/schema/beans"
  4.     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  5.     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
  6.     <!-- 表單控制器 -->
  7.     <beanname="/userLogin.html"class="com.jwy.controller.UserLoginController">
  8.         <propertyname="commandClass">
  9.             <value>com.jwy.controller.User</value>
  10.         </property>
  11.         <!-- 輸入表單資料頁面 -->
  12.         <propertyname="formView">
  13.             <value>index.jsp</value>
  14.         </property>
  15.         <!-- 表單提交後轉入頁面 -->
  16.         <propertyname="successView">
  17.             <value>login.jsp</value>
  18.         </property>
  19.     </bean>
  20. </beans>


index.jsp:

  1. <%@ page language="java"contentType="text/html"pageEncoding="GBK"%>
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  3. <html>
  4.     <head>
  5.         <title>檔名對映控制器</title>
  6.         <!-- 
  7.     <link rel="stylesheet" type="text/css" href="styles.css"> 
  8.     -->
  9.         <styletype="text/css">
  10. <!--  
  11. .STYLE3 {  
  12.     font-size: 9pt  
  13. }  
  14. -->
  15. </style>
  16. </head>
  17.   <body>
  18.   <center>
  19.     <spanclass="STYLE3">使用者登入</span>
  20.   </center>
  21.     <formmethod="post"action="userLogin.html">
  22.     <center>${map.error }

    相關推薦

    Spring MVC 控制器實現驗證使用者登入驗證

    轉自:http://blog.csdn.net/happyunbound/article/details/8236106 web.xml: <?xmlversion="1.0"encoding="UTF-8"?> <

    Spring MVC-(Form)標簽-選按鈕(RadioButton)示例(轉載實踐)

    springmvc tro void cnblogs subscribe bin 應用 mat efi 以下內容翻譯自:https://www.tutorialspoint.com/springmvc/springmvc_radiobutton.htm 說明:示例基於Sp

    Spring MVC-(Form)標簽-下拉框(Dropdown)示例(轉載實踐)

    getcount pap number ima mvc框架 ati 讓我 lec 第一個 以下內容翻譯自:https://www.tutorialspoint.com/springmvc/springmvc_dropdown.htm 說明:示例基於Spring MVC 4

    Spring MVC筆記(三) Spring MVC處理

    名稱 command -i mat ppi post doctype form hello 創建動態WEB工程 FormHandling,並添加SpringMVC相關jar包(同Hello world示例一致),添加DispatcherServlet配置,如下: web.

    [Spring MVC] 提交日期轉換問題,比如可能導致封裝實體類時400錯誤

    new tac med tab mat -m bin Edito ack   三種格式的InitBinder @InitBinder//https://stackoverflow.com/questions/20616319/the-request-sent-by-the

    Spring Mvc上傳404錯誤

    404錯誤是找不到檔案 500是邏輯錯誤 以下是我的表單提交 <form action="${pageContext.request.contextPath }/FirstController.6b" method="post" enctype="multipart/for

    Spring MVC 提交 出現400 Bad Request

    因為是form表單中有日期,Spring不知道該如何轉換,解決辦法 是在實體類的日期屬性上加 @DateTimeFormat(pattern="yyyy-MM-dd")註解。 參考自:http://

    Spring MVC----標簽庫

    tex jsp tab 單選 cti pat items ons put Spring MVC 表單標簽庫: 聲明表單標簽庫   在使用 SpringMVC 的時候我們可以使用 Spring 封裝的一系列表單標簽,這些標簽都可以訪問到 ModelMap 中的內容。我們

    spring boot 驗證

    1.2 取值 not p s 技術分享 tro otn alt 技術   1 設置某個字段的取值範圍   1.1 取值範圍驗證:@Min,@Max   ① 實例類的屬性添加註解@Min         ② Controller中傳入參數使用@Valid註解

    Spring Boot 驗證

    Spring Boot 表單驗證篇 摘要: 原創出處:www.bysocket.com 泥瓦匠BYSocket 希望轉載,保留摘要,謝謝! “初學者的心充滿各種可能性,老手的卻不多” 本文提綱 1 spring-boot-starter-validation 依賴概述 1.1 spr

    spring boot驗證 及使用AOP處理

    一、表單驗證1、當前臺傳入的引數過多是可以用一個物件來對屬性進行接收@PostMapping(value="/girl") public Girl addGirl(Girl girl){ girl.setAge(girl.getAge()); girl.setCupSi

    ASP.NET MVC5+EF6+EasyUI 後臺管理系統(33)-MVC 驗證

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel.DataAnnotations; using System.Web.Mvc; u

    ASP.NET MVC/Core提交後臺模型二級屬性驗證問題

    起因 這個是網友在官網論壇的提問:https://fineui.com/bbs/forum.php?mod=viewthread&tid=22237     重新問題 本著務實求真的態度,我們先來複現這個問題。首先頁面截圖是這樣的:   類 

    關於(輸入)常用的驗證

    content user urn doctype mage tran nav pid clas 現在輸入經常通過ajax提交,所以我也沒有直接寫表單的驗證。凡是輸入其實都是可以驗證的。說到驗證,我們習慣於在輸入之後馬上就能返回結果,在這一點上ajax能有不錯的效果。但是大部

    html中提交實現不跳轉頁面處理返回值

    html value put 提示 pan sdn type detail all <html> <head> <script type="text/javascript" src="h

    利用JS提交的幾種方法和驗證(必看篇)

    www contain 功能 ner ble 四種 利用 comm pac 第一種方式:表單提交,在form標簽中增加onsubmit事件來判斷表單提交是否成功 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

    Asp.net MVC4高級編程學習筆記-模型學習第五課MVC和HTML輔助方法20171101

    流量 取值 工作 sin 輔助 一個點 大量 元數據 view MVC表單和HTML輔助方法 一、表單的使用。 表單中的action與method特性。Action表示表單要提交往那裏,因此這裏就有一個URL。這個URL可以是相對或絕對地址。表單默認的method屬性值是g

    Spring MVC筆記(八) 控制器類名稱處理映射

    return https bst protect urn location utf-8 r.java 訪問 ControllerClassNameHandlerMapping類是基於約定的處理程序映射類,它將URL請求映射到配置中提到的控制器的名稱。這個類接受控制器名稱並將

    【java學習】spring mvc 公共dao的實現,定義基本的增刪改查

    pri 代碼 部分 lec sse encoding del epo repos 接口類:    package com.blog.db.dao; import com.blog.util.Pagination; import java.util.Lis

    Spring MVC中前端控制器攔截問題

    AS ont servle style map ram 所有 問題 name <!-- 前端控制器 --> <servlet> <servlet-name>ssm</servlet-name>