IDEA_15构建SSM登录功能(2)
IDEA_15构建SSM登录功能(2)
低调的AckMan 发表于1年前
IDEA_15构建SSM登录功能(2)
  • 发表于 1年前
  • 阅读 568
  • 收藏 3
  • 点赞 1
  • 评论 2

标题:腾讯云 新注册用户域名抢购1元起>>>   

项目构建图

AccountController

package com.ninemax.controller;

import com.ninemax.model.AccountModel;
import com.ninemax.service.AccountService;
import com.ninemax.utils.Md5Utils;
import com.ninemax.utils.ValidateCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.imageio.ImageIO;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;

/**
 * Created by AckMan on 2016/8/10.
 */
@Controller
@RequestMapping("/account")
public class AccountController {

    @Autowired
    @Qualifier("accountServiceImpl")
    private AccountService accountService;

    Boolean flag = false;

    /**
     * 帐号注册
     *
     * @param request 请求
     * @param response 响应
     * @param account 帐号实体类
     * @return
     */
    @RequestMapping(value = "/accountRegister")
    public String  accountRegister(HttpServletRequest request, HttpServletResponse response, AccountModel account){

        if(StringUtils.isEmpty(request.getParameter("email"))) {
           // flag = accountService.accountRegister(account);
            flag = accountService.accountRegister(request.getParameter("accountNumber"),request.getParameter("accountPassword"));
        }else{
            //flag = accountService.accountRegisterByEmail(account);
            flag = accountService.accountRegisterByEmail(request.getParameter("email"),request.getParameter("accountKey"));
        }
        if(flag){
            return "/account/login";
        }else{
            return "/account/register";
        }
    }

    /**
     * 用户登录
     *
     * @param request
     * @param response
     * @param session
     * @return
     */
    @RequestMapping(value = "/accountLogin")
    public String  accountLogin(HttpServletRequest request, HttpServletResponse response, HttpSession session,AccountModel account){

        // 校验验证码是否正确
        if ("".equals(request.getParameter("validateCode"))|| !request.getParameter("validateCode").equals(session.getAttribute("validateCode"))) {

            return "redirect:/";

        }else{

            if(StringUtils.isEmpty(request.getParameter("accountKey"))){
                //flag = accountService.accountLogin(account);
                flag = accountService.accountLogin(request.getParameter("accountNumber"),request.getParameter("accountPassword"));
            }else{
                flag = accountService.keyLogin(request.getParameter("accountKey"));
            }
            if(flag){
                return "/home/home";
            }else{
                return "/account/login";
            }
        }
    }

    /**
     * 用户找回密码
     *
     * @param request
     * @param response
     * @return
     */
    @RequestMapping(value="/findAccountPassword")
    public String findAccountPassword(HttpServletRequest request,HttpServletResponse response,HttpSession session,AccountModel account) {

        if (StringUtils.isEmpty(request.getParameter("accountKey"))) {

            if (!Md5Utils.md5Encode(request.getParameter("emailCode")).equals(accountService.findCodeByEmail(request.getParameter("email")))) {
                return "/account/forget";
            } else {
               // flag = accountService.findAccountPasswordByEmail(account);
                flag = accountService.findAccountPasswordByEmai(request.getParameter("accountPassword"),request.getParameter("email"));
            }
        }else{
            //flag = accountService.findAccountPasswordByKey(account);
            flag = accountService.findAccountPasswordByKey(request.getParameter("accountPassword"),request.getParameter("accountKey"));
        }
        if (flag) {
            return "/account/login";
        } else {
            return "/account/forget";
        }
    }

    /**
     * 查看邮件是否存在
     *
     * @param request
     * @param response
     */
    @RequestMapping(value = "/queryEmailIsExist")
    public void queryEmailIsExist( HttpServletRequest request,HttpServletResponse response){

        List<AccountModel> list = accountService.queryEmailIsExist(request.getParameter("email"));

        System.out.print(list.size());
        try {
            // 设置ajax返回类型
            response.setContentType("text/html;charset=UTF-8");
            // 得到输出流
            OutputStream printWriter = response.getOutputStream();
            // 输出提示信息
            if(list.size()==0){
                printWriter.write("isNotExist".getBytes());
            }else{
                printWriter.write("isExist".getBytes());
            }
            // 关闭链接
            printWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * 生成验证码
     *
     * @param request
     * @param response
     * @throws Exception
     */
    @RequestMapping(value = "/validateCode")
    public void validateCode(HttpServletRequest request,HttpServletResponse response) throws Exception {
        // 设置响应头信息
        response.setHeader("Cache-Control", "no-cache");
        // 返回一个新的验证码
        String verifyCode = ValidateCode.generateTextCode(ValidateCode.TYPE_NUM_ONLY, 4, null);
        // 将新的验证码放入到session里面
        request.getSession().setAttribute("validateCode", verifyCode);
        // 设置响应类型
        response.setContentType("image/jpeg");
        // 生成验证码图片
        BufferedImage bim = ValidateCode.generateImageCode(verifyCode, 120, 40,4, true, Color.white, Color.BLACK, null);
        // 渲染页面
        ImageIO.write(bim, "JPEG", response.getOutputStream());
    }

}

EmailController

package com.ninemax.controller;


import com.ninemax.model.EmailModel;
import com.ninemax.service.AccountService;
import com.ninemax.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;

/**
 * Created by AckMan on 2016/8/24.
 */
@Controller
@RequestMapping("/email")
public class EmailController {
    //@Resource
    @Autowired
    @Qualifier("emailServiceImpl")
    private EmailService emailService;

    @Autowired
    @Qualifier("accountServiceImpl")
    private AccountService accountService;

    @RequestMapping(value = "/sendEmail")
    public void sendEmail(HttpServletRequest request,HttpServletResponse response, String em){
        // 设置邮件服务器信息
        EmailModel email = new EmailModel();
        // 读取配置文件
        Properties prop = new Properties();
        try {
            // 加载配置文件
            prop.load(EmailController.class.getClassLoader().getResourceAsStream("email.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        // 设置邮件信息
        email.setMailServerHost(prop.getProperty("ServerHost"));
        email.setMailServerPort(prop.getProperty("ServerPort"));
        email.setValidate(true);
        email.setUserName(prop.getProperty("UserName"));
        email.setPassword(prop.getProperty("Password"));
        email.setFromAddress(prop.getProperty("FromAddress"));
        email.setToAddress(em);
        email.setSubject(prop.getProperty("Subject"));
        // 设置邮件内容
        StringBuffer buffer = new StringBuffer();
        // 产生验证码
        int key = (int)(Math.random()*1000000);
        // 将验证码和EMAIL存储到数据库
//        accountService.accountRegisterByEmail(em);
//        accountService.accountRegisterByKey(String.valueOf(key));
        email.setContent("KEY:"+key);
        // 发送文本格式邮件
        boolean flag = emailService.sendTextMail(email);
        // 设置ajax返回类型
        response.setContentType("text/html;charset=UTF-8");
        // 得到输出流
        try {
            OutputStream printWriter = response.getOutputStream();

            if(flag){
                System.out.print("SEND SUCCESS");
                printWriter.write("success".getBytes());
            }else{
                printWriter.write("fail".getBytes());
                System.out.print("SEND FAIL");
            }
            //  关闭流
            printWriter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

AccountService

package com.ninemax.service;

import com.ninemax.model.AccountModel;

import java.util.List;

/**
 * Created by AckMan on 2016/8/10.
 */
public interface AccountService {

    /**
     * 利用帐号密码注册
     * @param account 实体类
     * @return
     */
    public boolean accountRegister(AccountModel account);

    /**
     * 利用帐号密码注册
     * @param accountNumber
     * @param accountPassword
     * @return
     */
    public boolean accountRegister(String accountNumber,String accountPassword);

    /**
     * 利用邮箱注册
     * @param account 实体类
     * @return
     */
    public boolean accountRegisterByEmail(AccountModel account);

    /**
     * 利用邮箱注册
     * @param email
     * @param accountKey
     * @return
     */
    public boolean accountRegisterByEmail(String email,String accountKey);

    /**
     * 帐号密码登录
     * @param account 实体类
     * @return
     */
    public boolean accountLogin(AccountModel account);

    /**
     * 帐号密码登录
     * @param accountNumber
     * @param accountPassword
     * @return
     */
    public boolean accountLogin(String accountNumber,String accountPassword);

    /**
     * KEY登录
     * @param accountKey KEY
     * @return
     */
    public boolean keyLogin(String accountKey);

    /**
     * 通过KEY值修改密码
     * @param account
     * @return
     */
    public boolean findAccountPasswordByKey(AccountModel account);

    /**
     * 通过KEY值修改密码
     * @param accountPassword
     * @param accountKey
     * @return
     */
    public boolean findAccountPasswordByKey(String accountPassword,String accountKey);

    /**
     * 通过Email修改密码
     * @param account
     * @return
     */
    public boolean findAccountPasswordByEmail(AccountModel account);

    /**
     * 过Email修改密码
     * @param accountPassword
     * @param email
     * @return
     */
    public boolean findAccountPasswordByEmai(String accountPassword,String email);

    /**
     * 通过Email找到Code
     * @param email
     * @return
     */
    public String findCodeByEmail(String email);

    /**
     * 查看邮件是否存在
     * @param email
     */
    public List<AccountModel> queryEmailIsExist(String email);

    /**
     * 用户退出
     * @return
     */
    public boolean accountLoginOut();
}

EmailService

package com.ninemax.service;

import com.ninemax.model.EmailModel;

/**
 * Created by AckMan on 2016/8/24.
 */
public interface EmailService {
    // 发送html格式邮件
    public boolean sendHtmlMail(EmailModel email);
    // 设置发送邮件的内容
    public boolean sendTextMail(EmailModel email);
}

AccountServiceImpl

package com.ninemax.service.impl;

import com.ninemax.dao.AccountMapper;
import com.ninemax.model.AccountModel;
import com.ninemax.service.AccountService;
import com.ninemax.utils.Md5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Created by AckMan on 2016/8/10.
 */
@Service("accountServiceImpl")
public class AccountServiceImpl implements AccountService {

    @Autowired
    private AccountMapper accountMapper;

    @Override
    public boolean accountRegister(AccountModel account) {
        return accountMapper.registerAccount(account);
    }

    @Override
    public boolean accountRegister( String accountNumber, String accountPassword) {
        return accountMapper.registerAccountByMD5(accountNumber, Md5Utils.md5Encode(accountPassword));
    }

    @Override
    public boolean accountRegisterByEmail(AccountModel account) {

        return accountMapper.registerAccountByEmail(account);
    }

    @Override
    public boolean accountRegisterByEmail(String email, String accountKey) {
        return accountMapper.registerAccountByEmailByMD5(email,Md5Utils.md5Encode(accountKey));
    }

    @Override
    public boolean accountLogin(AccountModel account){

        List<AccountModel> list = accountMapper.loginAcount(account);

        if(list.size()==0){
            return false;
        }else {
            return true;
        }
    }

    @Override
    public boolean accountLogin(String accountNumber, String accountPassword) {

        List<AccountModel> list = accountMapper.loginAccountByMD5(accountNumber,Md5Utils.md5Encode(accountPassword));

        if(list.size()==0){
            return false;
        }else{
            return true;
        }
    }


    @Override
    public boolean keyLogin(String accountKey) {

        String result = Md5Utils.md5Encode("accountKey");

        System.out.println(result);

        List<AccountModel> list = accountMapper.loginAcountByKey(Md5Utils.md5Encode(accountKey));

        System.out.print(list.size());

        if (list.size()==0) {
            return false;
        } else {
            return true;
        }
    }

    @Override
    public boolean findAccountPasswordByKey(AccountModel account) {
        return  accountMapper.findAccountPasswordByKey(account);
    }

    @Override
    public boolean findAccountPasswordByKey(String accountPassword, String accountKey) {
        return accountMapper.findAccountPasswordByKeyByMD5(Md5Utils.md5Encode(accountPassword),Md5Utils.md5Encode(accountKey));
    }


    @Override
    public boolean findAccountPasswordByEmail(AccountModel account) {
        return accountMapper.findAccountPasswordByEmail(account);
    }

    @Override
    public boolean findAccountPasswordByEmai(String accountPassword, String email) {
        return accountMapper.findAccountPasswordByEmailByMD5(Md5Utils.md5Encode(accountPassword),email);
    }


    @Override
    public String findCodeByEmail(String email) {

        return accountMapper.findCodeByEmail(email);
    }

    @Override
    public List<AccountModel> queryEmailIsExist(String email) {
        return accountMapper.queryEmailIsExist(email);
    }

    @Override
    public boolean accountLoginOut() {
        return false;
    }
}

EmailServiceImpl

package com.ninemax.service.impl;

import com.ninemax.model.EmailModel;
import com.ninemax.service.EmailService;
import com.ninemax.utils.MyAuthenticator;
import org.springframework.stereotype.Service;

import javax.mail.Address;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Date;
import java.util.Properties;

/**
 * Created by AckMan on 2016/8/24.
 */
@Service("emailServiceImpl")
public class EmailServiceImpl implements EmailService{

    @Override
    public boolean sendTextMail(EmailModel email) {
        // 判断是否是要身份认证
        MyAuthenticator authenticator = null;
        // 获取邮件服务
        Properties prop = email.getProperties();
        // 若验证码正确,则将用户名和密码注入到认证器中
        if(email.isValidate()){
            authenticator = new MyAuthenticator(email.getUserName(),email.getPassword());
        }
        // 根据邮件会话属性和密码验证器构造一个发送邮件的session
        Session sendEmailSession = Session.getDefaultInstance(prop,authenticator);
        try {
            // 根据session创建邮件消息
            Message mailMessage = new MimeMessage(sendEmailSession);
            // 创建邮件发送者地址
            Address from = new InternetAddress(email.getFromAddress());
            // 设置邮件消息的发送者
            mailMessage.setFrom(from);
            // 创建邮件消息的接收者
            Address to = new InternetAddress(email.getToAddress());
            // 设置邮件消息的接收者
            mailMessage.setRecipient(Message.RecipientType.TO,to);
            // 设置邮件消息的主题
            mailMessage.setSubject(email.getSubject());
            // 设置邮件消息发送的时间
            mailMessage.setSentDate(new Date());
            // 设置邮件消息的主要内容
            mailMessage.setText(email.getContent());
            //  邮件发送
            Transport.send(mailMessage);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return false;
    }
    @Override
    public boolean sendHtmlMail(EmailModel email) {
        return false;
    }


}

AccountMapper(映射接口)

package com.ninemax.dao;

import com.ninemax.model.AccountModel;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by AckMan on 2016/8/10.
 */
@Repository
public interface AccountMapper {

    public boolean registerAccount(AccountModel account);

    public boolean registerAccountByMD5(@Param(value="accountNumber") String accountNumber, @Param(value="accountPassword") String accountPassword);

    public boolean registerAccountByEmail(AccountModel account);

    @Insert("INSERT INTO account(email,account_key) VALUES (#{email},#{accountKey})")
    public boolean registerAccountByEmailByMD5(@Param(value="email") String email,@Param(value="accountKey") String accountKey);

    public List<AccountModel> loginAcount(AccountModel account);

    @Select("SELECT * FROM account WHERE account_number=#{accountNumber} AND account_password=#{accountPassword}")
    public List<AccountModel> loginAccountByMD5(@Param(value="accountNumber") String accountNumber,@Param(value="accountPassword") String accountPassword);

    @Select("SELECT * FROM account WHERE  account_key = #{0}")
    public List<AccountModel> loginAcountByKey(String accountKey);

    public boolean findAccountPasswordByKey(AccountModel account);

    @Update("UPDATE account SET account_password = #{accountPassword} WHERE account_key = #{accountKey}")
    public boolean findAccountPasswordByKeyByMD5(@Param(value="accountPassword") String accountPassword,@Param(value="accountKey") String accountKey);

    public boolean findAccountPasswordByEmail(AccountModel account);

    @Update("UPDATE account SET account_password = #{accountPassword} WHERE email = #{email}")
    public boolean findAccountPasswordByEmailByMD5(@Param(value="accountPassword") String accountPassword,@Param(value="email") String email);

    @Select("SELECT account_key FROM account WHERE email = #{email}")
    public String findCodeByEmail(@Param(value="email") String email);

    @Select("SELECT * FROM account WHERE email = #{email}")
    public List<AccountModel> queryEmailIsExist(@Param(value = "email") String email);

}

AccountMapper.xml(映射接口配置文件)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.ninemax.dao.AccountMapper">
    <resultMap type="AccountModel" id="AccountModelMap">
        <result property="accountId" column="account_id"/>
        <result property="accountNumber" column="account_number" />
        <result property="accountPassword" column="account_password"/>
        <result property="accountKey" column="account_key"/>
        <result property="accountRank" column="account_rank"/>
        <result property="accountGrade" column="account_grade"/>
        <result property="email" column="email"/>
        <result property="createTime" column="createtime"/>
        <result property="createPerson" column="createperson"/>
        <result property="flag" column="flag"/>
    </resultMap>

    <insert id="registerAccount" parameterType="AccountModel" >
        INSERT INTO account(account_number,account_password)
        VALUES (#{accountNumber},#{accountPassword})
    </insert>

    <insert id="registerAccountByMD5" parameterType="String">
        INSERT INTO account(account_number,account_password)
        VALUES (#{accountNumber},#{accountPassword})
    </insert>

    <insert id="registerAccountByEmail" parameterType="AccountModel">
        INSERT INTO account(email,account_key)
        VALUES (#{email},#{accountKey})
    </insert>

    <!--<insert id="registerAccountByEmailByMD5" parameterType="String">-->
        <!--INSERT  INTO account(email,account_key)-->
        <!--VALUES (#{email},#{accountKey})-->
    <!--</insert>-->

    <select id="loginAcount" parameterType="AccountModel" resultType="list" resultMap="AccountModelMap">
        SELECT * FROM account
        WHERE account_number=#{accountNumber} AND account_password=#{accountPassword}
    </select>

    <!--<select id="loginAcountByKey" parameterType="String" resultType="list" resultMap="AccountModelMap">-->
        <!--SELECT * FROM account-->
        <!--WHERE  account_key = #{accountKey}-->
    <!--</select>-->

    <update id="findAccountPasswordByKey" parameterType="AccountModel" >
        UPDATE account SET account_password = #{accountPassword}
        WHERE account_key = #{accountKey}
    </update>

    <update id="findAccountPasswordByEmail" parameterType="AccountModel">
        UPDATE account SET account_password = #{accountPassword}
        WHERE email = #{email}
    </update>

    <!--<select id="findCodeByEmail" parameterType="String" resultType="String" >-->
        <!--SELECT account_key FROM account-->
        <!--WHERE email = #{#email}-->
    <!--</select>-->

    <!--<select id="queryEmailIsExist" parameterType="String" resultType="String" >-->
        <!--SELECT email FROM account-->
        <!--WHERE email = #{#email}-->
    <!--</select>-->

</mapper>

mvc-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:task="http://www.springframework.org/schema/task"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd">

    <!-- 自动扫描包 -->
    <context:component-scan base-package="com.ninemax"/>

    <!-- 配置注解扫描 -->
    <mvc:annotation-driven/>

    <!-- 配置定时器注解扫描 -->
    <task:annotation-driven/>

    <!-- 配置定时任务 -->
    <task:scheduled-tasks scheduler="myScheduler">
        <task:scheduled ref="scheduledTaskManager" method="autoCardCalculate" cron="1/5 * * * * *"/>
    </task:scheduled-tasks>
    <task:scheduler id="myScheduler" pool-size="1000"/>

    <!-- 配置资源文件目录 -->
    <mvc:resources mapping="/resource/**" location="/resource/"/>

    <!-- 配置页面解析 -->
    <bean id="viewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
        <property name="prefix" value="/view"/>
        <property name="suffix" value=".jsp"/>
    </bean>

    <!-- 配置文件上传 -->
    <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
        <property name="maxUploadSize" value="1000000000"/>
    </bean>

</beans>

spring-mybatis.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop"
       xmlns:context="http://www.springframework.org/schema/context"
       xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
    <!-- Spring bean-->
    <context:component-scan base-package="com.ninemax">
        <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
    <!-- data source -->
    <context:property-placeholder location="classpath:jdbc.properties"/>
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="url" value="${jdbc.url}"/>
        <property name="driverClassName" value="${jdbc.driver}"/>
        <property name="username" value="${jdbc.username}"/>
        <property name="password" value="${jdbc.password}"/>
        <property name="initialSize" value="${jdbc.initialSize}"/>
        <property name="minIdle" value="${jdbc.minIdle}"/>
        <property name="maxIdle" value="${jdbc.maxIdle}"/>
        <property name="maxActive" value="${jdbc.maxActive}"/>
        <property name="maxWait" value="${jdbc.maxWait}"/>
    </bean>
    <!-- 配置事务管理器 -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>
    <!-- MyBatis SessionFactory -->
    <bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"/>
        <property name="typeAliasesPackage" value="com.ninemax.model"/>
    </bean>
    <!-- MyBatis auto scannner Mapper -->
    <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
        <property name="basePackage" value="com.ninemax.dao"/>
    </bean>
</beans>

jdbc.properties

jdbc.driver=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://localhost:3306/ssm
jdbc.username=root
jdbc.password=root
jdbc.initialSize=0
jdbc.maxActive=20
jdbc.maxIdle=20
jdbc.minIdle=1
jdbc.maxWait=60000

email.properties

ServerHost = smtp.163.com

ServerPort = 25

UserName = xxx@163.com

Password = xxx

FromAddress = xxx@163.com
//测试Java程序发送邮件
Subject = ValidateCode

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
         version="2.4">
    <display-name>Archetype Created Web Application</display-name>
    <!-- start page -->
    <welcome-file-list>
        <welcome-file>view/account/login.jsp</welcome-file>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
    <!--Spring container-->
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <!-- spring mybatis -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath:spring-mybatis.xml</param-value>
    </context-param>
    <!-- char encoding -->
    <filter>
        <filter-name>encodingFilter</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>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <!-- SpringMVC -->
    <servlet>
        <servlet-name>mvc</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:mvc-servlet.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>mvc</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

login.jsp(登录页面)

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <base href="<%=basePath%>">
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title>Member Login</title>
    <link href="resource/css/style.css" rel='stylesheet' type='text/css'/>
</head>
<body>
<!-----start-main---->
<div class="main">
    <div class="login-form">
        <h1>Member Login</h1>
        <div class="head">
            <img src="resource/images/user.png" alt="Personal Photo"/>
        </div>
        <form action="account/accountLogin" method="post">
            <input type="text" name="accountNumber" id="accountNumber" placeholder="AccountNumber" style="display: inline" />
            <input type="password" name="accountPassword" id="accountPassword" placeholder="AccountPassword" style="display: inline" />
            <input type="text" name="accountKey" id="accountKey" placeholder="AccountKey" style="display: inline;" />
            <input type="text" name="validateCode" placeholder="ValidateCode"  style="width:50%;" />
            <a href="#"><img id="validateCodeImg" src="account/validateCode"/></a></br></br>
            <div class="submit">
                <input type="submit" value="LOGIN" />
            </div>
            <p>
                <a href="view/account/register.jsp">Register</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <a href="view/account/forget.jsp">ForgetPassword</a>
            </p>
        </form>
    </div>
    <!--//End-login-form-->
</div>
<script src="resource/js/jquery-1.11.2.min.js"></script>
<script type="text/javascript">

    $("#validateCodeImg").click(function () {
        //如果需要点击图片改变图片的内容,则必须添加时间戳
        $("#validateCodeImg").attr("src", "account/validateCode?rmd=" + new Date().getTime())

    });

    $("input").blur(function(){

        if($("#accountNumber").val().length!=0){
            $("#accountKey").css("display","none");
        }else{
            $("#accountNumber").css("display","none");
            $("#accountPassword").css("display","none");
        }
    });

</script>
</body>
</html>

register.jsp(注册页面)

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <base href="<%=basePath%>">
    <title>Member Register</title>
    <link href='http://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
    <link href="resource/css/register.css" rel='stylesheet' type='text/css'>
<body>
<div class="login-block">
    <form action="account/accountRegister">
        <h1>Member Register</h1>
        <input type="text" name="accountNumber" placeholder="AccountNumber" id="username"  />
        <input type="password" name="accountPassword" placeholder="AccountPassword" id="password"/>
        <input type="email" id="email" name="email" placeholder="E-mail" id="email" />
        <input type="text" id="code" name="accountKey" placeholder="KEY"  style="display: none;" />
        <button type="button"  id="btnCode" style="display: none;">发送KEY</button>&nbsp;
        <span id="info1" style="display: none;color:red;">Email已注册!</span>
        <span id="info2" style="display: none;color:red;">Email可用!</span>
        <a href="view/account/register.jsp"><button type="button">Return</button></a>&nbsp;&nbsp;
        <button id="btn">Submit</button>
    </form>
</div>
<script src="resource/js/jquery-1.11.2.min.js" ></script>
<script type="text/javascript">

    // 选择注册方式
    $("input").blur(function(){

        if( $("#email").val().length==0){
            $("#email").css("display","none");
        }else{
            $("#username").css("display","none");
            $("#password").css("display","none");
            $("#code").css("display","inline");
            $("#btnCode").css("display","inline");
        }

    });
    // 查看邮件是否存在
    $("#email").blur(function(){

        var email = $("#email").val();

        $.ajax({
            url:'account/queryEmailIsExist',
            type:"POST",
            data: {"email":email},
            success:function(data){

                    if(data=="isExist"){
                        $("#info1").css("display","inline");
                        $("#info2").css("display","none");
                        $("#btnCode").attr("disabled","disabled");
                        $("#btn").attr("disabled","disabled");
                    }else{
                        $("#info1").css("display","none");
                        $("#info2").css("display","inline");
                        $("#btnCode").removeAttr("disabled");
                        $("#btn").removeAttr("disabled");
                    }
            },
            error:function(data){

                alert("Server Error!");
            }
        });
    // 邮件点击事件
    $("#btnCode").click(function(){

        var email = $("#email").val();

        if(email!=null){
            $.ajax({
                url:'email/sendEmail',
                type:'POST',
                data:{"em":email},
                success:function(data){
                    if(data=="success"){
                        alert("Send Success,Please Input Your ValidateCode!");
                    }else{
                        alert("Send Fail,Please Send E-mail Again!");
                    }
                },
                error:function(data){
                    alert("Server Error!");
                }
            });
        }else{
            alert("Email is not empty!");
        }
    });

});
</script>
</body>
</html>

forget.jsp(忘记密码页面)

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <base href="<%=basePath%>">
    <title>Member ForgetPassword</title>
    <link href='http://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
    <link href="resource/css/register.css" rel='stylesheet' type='text/css'>
</head>
<body>
<div class="login-block">
    <form action="account/findAccountPassword">
        <h1>ForgetPassword</h1>
        <input type="text" name="accountKey" placeholder="AccountKey" id="username" style="display: inline;" />
        <input type="email" name="email" placeholder="E-mail" id="email" style="display: inline;" />
        <input type="text" name="emailCode" placeholder="EmailCode" id="code" style="display: none" />
        <input type="password" name="accountPassword" placeholder="AccountPassword" id="password" style="display: none;" />
        <a href="view/account/forget.jsp"><button type="button">Return</button></a>&nbsp;&nbsp;
        <span id="info" style="display: none;color:red;">Email不存在!</span>
        <button id="btn">Submit</button>
    </form>
</div>
<script src="resource/js/jquery-1.11.2.min.js" ></script>
<script type="text/javascript">

    // 选择修改密码方式
    $("input").blur(function(){

        var email = $("#email").val();

        if(email.length==0){
            $("#email").css("display","none");
        }else{
            $("#username").css("display","none");
            $("#code").css("display","inline");

            // 查看邮件是否存在
                $.ajax({
                    url:'account/queryEmailIsExist',
                    type:"POST",
                    data: {"email":email},
                    success:function(data){

                        if(data == "isExist"){
                            $("#info").css("display","none");
                            $("#btn").removeAttr("disabled");
                        }else{
                            $("#info").css("display","inline");
                            $("#btn").attr("disabled","disabled");
                        }
                    },
                    error:function(data){

                        alert("Server Error!");
                    }
                });
        }
        $("#password").css("display","inline");
    });

</script>
</body>
</html>

效果图

共有 人打赏支持
低调的AckMan
粉丝 44
博文 317
码字总数 134757
评论 (2)
OldCoffee
全拷下来也 还是不行哈:fearful:
低调的AckMan

引用来自“OldCoffee”的评论

全拷下来也 还是不行哈:fearful:
:joy:
×
低调的AckMan
谢谢观众老爷们的赏赐,小弟我会再接再厉的!
* 金额(元)
¥1 ¥5 ¥10 ¥20 其他金额
打赏人
留言
* 支付类型
微信扫码支付
打赏金额:
已支付成功
打赏金额: