SSM(Spring+SpringMVC+Mybatis)登录实例

1.创建Web Project项目
2.加载jar包

Mybatis和spring整合包:mybatis-spring-1.2.2.jar;

Mybatis核心和Mybatis依赖包;

Spring的jar(包括springmvc的jar包);

数据库驱动包;

第三方数据库连接池;

点击下面链接可下载当前所需所有jar包:

点击打开链接

3.创建所需配置文件

创建Spring配置文件:
spring/applicationContext.xml:Spring配置文件(配置公用内容:数据源、事务);
spring/applicationContext-dao.xml:spring和mybatis整合的配置(SqlSessionFactory、mapper配置),配置与持久层相关接口的加载;
spring/applicationContext-service.xml:配置业务接口;
spring/springmvc.xml:springmvc的全局配置文件,整合过程中我们需要在这里配置组件扫描action,处理器映射器、处理器适配器和视图解析器。
创建Mybatis配置文件:
mybatis/SqlMapConfig.xml:mybatis全局配置文件。
配置文件:
log4j.properties:日志配置文件;
db.properties:数据库连接配置文件。

此项目目录如下:


4.properties配置文件源代码

log4j.properties配置文件基本不需要做任何修改。

  1. # Global logging configuration
  2. log4j.rootLogger=DEBUG, stdout
  3. # Console output...
  4. log4j.appender.stdout=org.apache.log4j.ConsoleAppender
  5. log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
  6. log4j.appender.stdout.layout.ConversionPattern=%5p [%t] - %m%n
db.properties里配置的是连接数据库所需的值,在这里统一管理。

  1. jdbc.driver=com.mysql.jdbc.Driver
  2. jdbc.url=jdbc:mysql: //localhost:3306/databasename
  3. jdbc.username=databaseusername
  4. jdbc.password=databasepassword
  5. jdbc.maxActive= 3
  6. jdbc.maxIdle= 1

5.准备环境

     在application.xml中配置数据源。

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc= "http://www.springframework.org/schema/mvc"
  3. xmlns:context= "http://www.springframework.org/schema/context"
  4. xmlns:aop= "http://www.springframework.org/schema/aop" xmlns:tx= "http://www.springframework.org/schema/tx"
  5. xsi:schemaLocation= "http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  7. http://www.springframework.org/schema/mvc
  8. http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
  9. http://www.springframework.org/schema/context
  10. http://www.springframework.org/schema/context/spring-context-3.1.xsd
  11. http://www.springframework.org/schema/aop
  12. http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
  13. http://www.springframework.org/schema/tx
  14. http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ">
  15. <!-- 加载数据库连接配置文件 -->
  16. <context:property-placeholder location="classpath:db.properties" />
  17. <!-- 数据库连接处dbcp -->
  18. <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
  19. destroy-method= "close">
  20. <property name="driverClassName" value="${jdbc.driver}" />
  21. <property name="url" value="${jdbc.url}" />
  22. <property name="username" value="${jdbc.username}" />
  23. <property name="password" value="${jdbc.password}" />
  24. <!-- 开发阶段数据库最大连接数建议设置小一点够用即可,设置为3 -->
  25. <property name="maxActive" value="${jdbc.maxActive}" />
  26. <property name="maxIdle" value="${jdbc.maxIdle}" />
  27. </bean>
  28. </beans>
    由spring管理sqlSessionFactory,在applicationContext-dao.xml中进行如下配置。

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc= "http://www.springframework.org/schema/mvc"
  3. xmlns:context= "http://www.springframework.org/schema/context"
  4. xmlns:aop= "http://www.springframework.org/schema/aop" xmlns:tx= "http://www.springframework.org/schema/tx"
  5. xsi:schemaLocation= "http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  7. http://www.springframework.org/schema/mvc
  8. http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
  9. http://www.springframework.org/schema/context
  10. http://www.springframework.org/schema/context/spring-context-3.1.xsd
  11. http://www.springframework.org/schema/aop
  12. http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
  13. http://www.springframework.org/schema/tx
  14. http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ">
  15. <!-- 配置SqlSessionFactory -->
  16. <bean id="sqlSessionFactoryBean" class="org.mybatis.spring.SqlSessionFactoryBean">
  17. <!-- 数据源 -->
  18. <property name="dataSource" ref="dataSource"/>
  19. <!-- 配置SqlMapConfig.xml -->
  20. <property name="configLocation" value="classpath:mybatis/SqlMapConfig.xml"/>
  21. </bean>
  22. </beans>
    在web.xml中进行加载spring容器和post乱码处理等配置。
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  3. xmlns= "http://java.sun.com/xml/ns/javaee" xmlns:web= "http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  4. xsi:schemaLocation= "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
  5. id= "WebApp_ID" version= "2.5">
  6. <display-name>mybatis1218_ssm </display-name>
  7. <!-- 加载spring容器 -->
  8. <context-param>
  9. <param-name>contextConfigLocation </param-name>
  10. <param-value>/WEB-INF/classes/spring/applicationContext.xml,/WEB-INF/classes/spring/applicationContext-*.xml </param-value>
  11. </context-param>
  12. <listener>
  13. <listener-class>org.springframework.web.context.ContextLoaderListener </listener-class>
  14. </listener>
  15. <!-- post乱码处理 -->
  16. <filter>
  17. <filter-name>CharacterEncodingFilter </filter-name>
  18. <filter-class>org.springframework.web.filter.CharacterEncodingFilter </filter-class>
  19. <init-param>
  20. <param-name>encoding </param-name>
  21. <param-value>utf-8 </param-value>
  22. </init-param>
  23. </filter>
  24. <filter-mapping>
  25. <filter-name>CharacterEncodingFilter </filter-name>
  26. <url-pattern>/* </url-pattern>
  27. </filter-mapping>
  28. <welcome-file-list>
  29. <welcome-file>index.html </welcome-file>
  30. <welcome-file>index.htm </welcome-file>
  31. <welcome-file>index.jsp </welcome-file>
  32. <welcome-file>default.html </welcome-file>
  33. <welcome-file>default.htm </welcome-file>
  34. <welcome-file>default.jsp </welcome-file>
  35. </welcome-file-list>
  36. </web-app>

6.整合持久层

    将Mybatis和Spring整合,目标是将生成的mapper交由spring管理,sqlSessionFactory交由spring来创建。

    有两种方法,一种是原始DAO方法,创建dao接口和dao实现类,在applicationContext.xml中为dao创建相应bean;第二种是使用动态代理的方法,并且使用mapper批量扫描器扫描mapper接口。此项目使用第二种方法。

    先从Mybatis逆向工程开始。Mybatis是ORM框架(对象关系映射),及表与对象之间的映射,与Hibernate相同,但Mybatis是一个不完全ORM框架,因为它需要程序员去编写SQL语句,自动去完成向SQL中映射输入参数,SQL查询结果映射成java对象。逆向工程可以使用插件的方式,也可以使用JAVA程序的方式,这里使用后者,程序里的内容也是基本固定的,我们只需要根据需要修改里边的XML文件即可,执行逆向工程生成所需po类、mapper接口和mapper.xml文件,后两者要放在同一个包内。逆向工程程序可从下面下载。

    点击打开链接

  下面是我的逆向工程中修改后的generatorConfig.xml文件,主要修改数据库连接信息、mapper接口与mapper.xml映射文件生成位置、所需生成表与表生成位置。

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE generatorConfiguration
  3. PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
  4. "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
  5. <generatorConfiguration>
  6. <context id="testTables" targetRuntime="MyBatis3">
  7. <commentGenerator>
  8. <!-- 是否去除自动生成的注释 true:是 : false:否 -->
  9. <property name="suppressAllComments" value="true" />
  10. </commentGenerator>
  11. <!--数据库连接的信息:驱动类、连接地址、用户名、密码 -->
  12. <jdbcConnection driverClass="com.mysql.jdbc.Driver"
  13. connectionURL= "jdbc:mysql://localhost:3306/safe_video" userId= "root"
  14. password= "password">
  15. </jdbcConnection>
  16. <!-- Oracle连接信息 -->
  17. <!-- <jdbcConnection driverClass="oracle.jdbc.OracleDriver"
  18. connectionURL="jdbc:oracle:thin:@127.0.0.1:1521:yycg"
  19. userId="yycg"
  20. password="yycg">
  21. </jdbcConnection> -->
  22. <!-- 默认false,把JDBC DECIMAL 和 NUMERIC 类型解析为 Integer,为 true时把JDBC DECIMAL 和
  23. NUMERIC 类型解析为java.math.BigDecimal -->
  24. <javaTypeResolver>
  25. <property name="forceBigDecimals" value="false" />
  26. </javaTypeResolver>
  27. <!-- targetProject:生成PO类的位置 -->
  28. <javaModelGenerator targetPackage="com.ssm.po"
  29. targetProject= ".\src">
  30. <!-- enableSubPackages:是否让schema作为包的后缀 -->
  31. <property name="enableSubPackages" value="false" />
  32. <!-- 从数据库返回的值被清理前后的空格 -->
  33. <property name="trimStrings" value="true" />
  34. </javaModelGenerator>
  35. <!-- targetProject:mapper映射文件生成的位置 -->
  36. <sqlMapGenerator targetPackage="com.ssm.mapper"
  37. targetProject= ".\src">
  38. <!-- enableSubPackages:是否让schema作为包的后缀 -->
  39. <property name="enableSubPackages" value="false" />
  40. </sqlMapGenerator>
  41. <!-- targetPackage:mapper接口生成的位置 -->
  42. <javaClientGenerator type="XMLMAPPER"
  43. targetPackage= "com.ssm.mapper"
  44. targetProject= ".\src">
  45. <!-- enableSubPackages:是否让schema作为包的后缀 -->
  46. <property name="enableSubPackages" value="false" />
  47. </javaClientGenerator>
  48. <!-- 指定数据库表 -->
  49. <table schema="" tableName="safe_user"> </table>
  50. <!-- 有些表的字段需要指定java类型
  51. <table schema="" tableName="">
  52. <columnOverride column="" javaType="" />
  53. </table> -->
  54. </context>
  55. </generatorConfiguration>
        将生成的mapper包和po包放在src下,修改Mybatis的配置文件SqlMapConfig.xml文件,可以进行缓存的全局配置、设置别名等。

  1. <?xml version="1.0" encoding="UTF-8" ?>
  2. <!DOCTYPE configuration
  3. PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
  4. "http://mybatis.org/dtd/mybatis-3-config.dtd">
  5. <configuration>
  6. <settings>
  7. <!-- 开启延迟加载 -->
  8. <setting name="lazyLoadingEnabled" value="true"/>
  9. <setting name="aggressiveLazyLoading" value="false"/>
  10. <!-- 打开二级缓存 -->
  11. <setting name="cacheEnabled" value="true"/>
  12. </settings>
  13. <!-- 配置别名 -->
  14. <typeAliases>
  15. <!-- 批量扫描po -->
  16. <package name="com.ssm.po"/>
  17. </typeAliases>
  18. <!-- 配置mapper映射文件 -->
  19. <mappers>
  20. </mappers>
  21. </configuration>

          在applicationContext-dao.xml中配置mapper(让spring生成动态代理),在beans中加入以下配置。

  1. <!-- 使用mapper批量扫描器扫描mapper接口
  2. 规则:mapper.xml和mapper.java在一个目录 且同名即可 
  3. 扫描出来mapper,自动让spring容器注册,bean的id就是mapper类名(首字母小写)
  4.  -->
  5. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
  6. <!-- 会话工厂 -->
  7. <property name="sqlSessionFactoryBeanName" value="sqlSessionFactoryBean"/>
  8.   <!-- 扫描包路径 
  9.   多个包中间用半角逗号分隔
  10.    -->
  11. <property name="basePackage" value="com.ssm.mapper"/>
  12. </bean>

7.整合业务层

    由Spring管理Service,Service通过Spring调用mapper,有Spring进行事务配置。

    开发Service接口。

[java]  view plain  copy
  1. <code class="language-html">package com.ssm.service;  
  2.   
  3. import com.ssm.po.SafeUser;  
  4.   
  5. public interface UserService {  
  6.       
  7.     /** 
  8.      * 登录验证 
  9.      * @param type 登录账号类型 
  10.      * @param account 登录账号 
  11.      * @param userPassword 密码 
  12.      * @return  validate true通过 false未通过 
  13.      * @throws Exception 
  14.      */  
  15.     public SafeUser loginValidate(String type, String account, String userPassword) throws Exception;  
  16. }  
  17. </code>  
        开发Service实现类,使用@Autowired注解自动注入mapper对象。

  1. package com.ssm.service.impl;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import com.ssm.mapper.SafeUserMapper;
  6. import com.ssm.po.SafeUser;
  7. import com.ssm.po.SafeUserExample;
  8. import com.ssm.service.UserService;
  9. public class UserServiceImpl implements UserService {
  10. @Autowired
  11. SafeUserMapper safeUserMapper;
  12. @Override
  13. public SafeUser loginValidate(String type, String account,
  14. String userPassword) throws Exception {
  15. List<SafeUser> users = new ArrayList<SafeUser>();
  16. //定义查询对象
  17. SafeUserExample userExample = new SafeUserExample();
  18. SafeUserExample.Criteria criteria = userExample.createCriteria();
  19. if (type.equals( "tel")) {
  20. //使用手机登录
  21. criteria.andUserTelEqualTo(account);
  22. } else if (type.equals( "email")) {
  23. //使用邮箱登录
  24. criteria.andUserEmailEqualTo(account);
  25. } else if (type.equals( "id")) {
  26. //使用ID登录
  27. criteria.andUserIdEqualTo(account);
  28. } else {
  29. return null;
  30. }
  31. criteria.andUserPasswordEqualTo(userPassword);
  32. users = safeUserMapper.selectByExample(userExample);
  33. if(users.size()== 1) {
  34. //找到一条记录,用户存在
  35. return users.get( 0);
  36. }
  37. return null;
  38. }
  39. }
        将Service借口交由Spring管理,在applicationContext-service.xml进行如下配置。

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc= "http://www.springframework.org/schema/mvc"
  3. xmlns:context= "http://www.springframework.org/schema/context"
  4. xmlns:aop= "http://www.springframework.org/schema/aop" xmlns:tx= "http://www.springframework.org/schema/tx"
  5. xsi:schemaLocation= "http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  7. http://www.springframework.org/schema/mvc
  8. http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
  9. http://www.springframework.org/schema/context
  10. http://www.springframework.org/schema/context/spring-context-3.1.xsd
  11. http://www.springframework.org/schema/aop
  12. http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
  13. http://www.springframework.org/schema/tx
  14. http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ">
  15. <!-- 用户管理 -->
  16. <bean id="userService" class="com.ssm.service.impl.UserServiceImpl"> </bean>
  17. </beans>
        采用声明式事务配置,在applicationContext.xml中配置事务。

  1. <!-- 事务管理器,mybatis使用jdbc事务管理-->
  2. <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  3. <!-- 数据源 -->
  4. <property name="dataSource" ref="dataSource" > </property>
  5. </bean>
  6. <!-- 通知 -->
  7. <tx:advice id="txAdvice" transaction-manager="transactionManager" >
  8. <!-- 配置传播行为 -->
  9. <tx:attributes>
  10. <tx:method name="save*" propagation="REQUIRED" rollback-for="Exception" />
  11. <tx:method name="insert*" propagation="REQUIRED" rollback-for="Exception"/>
  12. <tx:method name="update*" propagation="REQUIRED" rollback-for="Exception"/>
  13. <tx:method name="delete*" propagation="REQUIRED" rollback-for="Exception"/>
  14. <tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
  15. <tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
  16. <tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
  17. </tx:attributes>
  18. </tx:advice>
  19. <!-- aop配置 -->
  20. <aop:config>
  21. <aop:advisor advice-ref="txAdvice"
  22. pointcut= "execution(* com.ssm.service.impl.*.*(..))"/>
  23. </aop:config>

8.整合控制层

        在action中通过Spring调用Service。

        在web.xml中配置SpringMVC的前端控制器。

  1. <!-- 前端控制器 -->
  2. <servlet>
  3. <servlet-name>springmvc </servlet-name>
  4. <servlet-class>org.springframework.web.servlet.DispatcherServlet </servlet-class>
  5. <!-- contextConfigLocation指定 springmvc的全局配置文件 如果 contextConfigLocation不指定,默认找配置文件名称:servlet的name+"-servlet.xml" -->
  6. <init-param>
  7. <param-name>contextConfigLocation </param-name>
  8. <param-value>classpath:spring/springmvc.xml </param-value>
  9. </init-param>
  10. </servlet>
  11. <servlet-mapping>
  12. <servlet-name>springmvc </servlet-name>
  13. <url-pattern>*.action </url-pattern>
  14. </servlet-mapping>
        配置springmvc.xml。

  1. <beans xmlns="http://www.springframework.org/schema/beans"
  2. xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc= "http://www.springframework.org/schema/mvc"
  3. xmlns:context= "http://www.springframework.org/schema/context"
  4. xmlns:aop= "http://www.springframework.org/schema/aop" xmlns:tx= "http://www.springframework.org/schema/tx"
  5. xsi:schemaLocation= "http://www.springframework.org/schema/beans
  6. http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
  7. http://www.springframework.org/schema/mvc
  8. http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
  9. http://www.springframework.org/schema/context
  10. http://www.springframework.org/schema/context/spring-context-3.1.xsd
  11. http://www.springframework.org/schema/aop
  12. http://www.springframework.org/schema/aop/spring-aop-3.1.xsd
  13. http://www.springframework.org/schema/tx
  14. http://www.springframework.org/schema/tx/spring-tx-3.1.xsd ">
  15. <!-- 组件扫描action -->
  16. <context:component-scan base-package="com.ssm.action"> </context:component-scan>
  17. <!-- 处理器映射器 处理器适配器 -->
  18. <mvc:annotation-driven> </mvc:annotation-driven>
  19. <!-- 视图解析器 -->
  20. <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
  21. <!-- 视图的前缀 -->
  22. <property name="prefix" value="/WEB-INF/jsp/" />
  23. <!-- 视图的后缀 -->
  24. <property name="suffix" value=".jsp" />
  25. </bean>
  26. </beans>
        编写action,使用注解开发,在action包下创建UserAction.class,进行登录验证,如果成功就通过视图解析器进入“WEB-INF/jsp/test.jsp”,如果失败进入index.jsp。

  1. package com.ssm.action;
  2. import javax.servlet.http.HttpSession;
  3. import org.springframework.beans.factory.annotation.Autowired;
  4. import org.springframework.stereotype.Controller;
  5. import org.springframework.ui.Model;
  6. import org.springframework.web.bind.annotation.RequestMapping;
  7. import com.ssm.po.SafeUser;
  8. import com.ssm.service.UserService;
  9. @Controller
  10. @RequestMapping("/user")
  11. public class UserAction {
  12. @Autowired
  13. private UserService userService;
  14. @RequestMapping("/login")
  15. public String loginVailet(Model model, HttpSession session, String account, String pwd) throws Exception {
  16. SafeUser user = new SafeUser();
  17. user = userService.loginValidate("tel", account, pwd);
  18. if (user!=null) {
  19. session.setAttribute("user", user);
  20. return "test";
  21. }
  22. return "redirect:../index.jsp";
  23. }
  24. }

9.编写界面

        成功页面test.jsp,路径为WEB-INF/jsp/test.jsp。

  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2. <%
  3. String path = request.getContextPath();
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  5. %>
  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  7. <html>
  8. <head>
  9. <base href="<%=basePath%>">
  10. <title>主页 </title>
  11. <meta http-equiv="pragma" content="no-cache">
  12. <meta http-equiv="cache-control" content="no-cache">
  13. <meta http-equiv="expires" content="0">
  14. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  15. <meta http-equiv="description" content="This is my page">
  16. <!--
  17. <link rel="stylesheet" type="text/css" href="styles.css">
  18. -->
  19. </head>
  20. <body>
  21. ${user.userTel }
  22. </body>
  23. </html>
        index.jsp为登录页面,放在WebRoot下。

  1. <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
  2. <%
  3. String path = request.getContextPath();
  4. String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
  5. %>
  6. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  7. <html>
  8. <head>
  9. <base href="<%=basePath%>">
  10. <title>登录 </title>
  11. <meta http-equiv="pragma" content="no-cache">
  12. <meta http-equiv="cache-control" content="no-cache">
  13. <meta http-equiv="expires" content="0">
  14. <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
  15. <meta http-equiv="description" content="This is my page">
  16. <!--
  17. <link rel="stylesheet" type="text/css" href="styles.css">
  18. -->
  19. </head>
  20. <body>
  21. <form action="${pageContext.request.contextPath}/user/login.action" method="post" onsubmit="return logincheck();">
  22. <div class="login_row login_row_text">
  23. <label id="login_lab_user" class="login_lab">账号 </label>
  24. <input id="loginname" class="itext" type="text" name="account" tabindex="1" autocomplete="off"
  25. placeholder= "邮箱/用户名/已验证手机">
  26. </div>
  27. <div class="login_row login_row_text">
  28. <label id="login_lab_pwd" class="login_lab">密码 </label>
  29. <input id="signpwd" class="itext" type="password" name="pwd" tabindex="2" autocomplete="off"
  30. placeholder= "密码">
  31. </div>
  32. <div class="login_row">
  33. <input id="autologin" type="checkbox" name="autologin" tabindex="3">
  34. <label>自动登录 </label>
  35. <span id="spanfor"> <a target="_blank">忘记密码? </a> </span>
  36. </div>
  37. <div class="login_row">
  38. <input id="loginbut" type="submit" name="login_sub" value="登 录" tabindex="4">
  39. </div>
  40. <div id="meserror">
  41. <ul id="meserrorul">
  42. </ul>
  43. </div>
  44. </form>
  45. </body>
  46. </html>
前端控制器中过滤.action后缀的请求,通过SpringMVC配置文件springmvc.xml中context:component-scan扫描到到相应action中执行。

        接下来进入登录页面即index.jsp中测试即可。

        下面是工程源代码。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值