文档章节

IDEA_15构建SSM登录功能(2)

AK灬
 AK灬
发布于 2016/09/29 18:31
字数 3302
阅读 582
收藏 3
点赞 1
评论 3

项目构建图

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>

效果图

© 著作权归作者所有

共有 人打赏支持
AK灬

AK灬

粉丝 46
博文 324
码字总数 136677
作品 0
朝阳
后端工程师
加载中

评论(3)

f
flyGit
@Service("emailServiceImpl")
public class EmailServiceImpl implements EmailService{

@Override
public boolean sendTextMail(EmailModel email) {
// 判断是否是要身份认证
MyAuthenticator authenticator = null;
// 获取邮件服务
Properties prop = email.getProperties();

请问prop 变量的具体内容时什么,EmailModel 类的属性有哪些,这些属性又在哪赋值,都赋了哪些值。
AK灬
AK灬

引用来自“OldCoffee”的评论

全拷下来也 还是不行哈:fearful:
:joy:
OldCoffee
OldCoffee
全拷下来也 还是不行哈:fearful:
SSM框架-在实际项目中运行中的问题总结

由于问题是在框架搭建以及运行运行过程中,这边文章是写在完成之后,当时很多问题都没有截图保存,这里只能详细的描述一下问题所在。后续遇到问道问题会及时补充。 1 SSM框架中RESTful支持 ...

Bbigbug ⋅ 06/04 ⋅ 0

crossoverJie/SSM

使用Idea搭建的Maven项目,会不定期更新一些在实际开发中使用的技巧,没有复杂的业务流程,更不是XXXX系统,只有一些技术的分享 目录结构 ├── SSM-API // 通用API │ ├── src/main│ ├...

crossoverJie ⋅ 05/09 ⋅ 0

用resin启动项目,在IDEA下可以正常启动,resin直接war包启动,静态资源文件404

进来在研究resin,在IDEA下使用resin服务器启动一个SSM项目时,可以正常启动,使用的是resin3.1.8版本,修改了app-default.xml文件,将resin-file修改为default,所以在IDEA中可以正常使用; 但是同...

sunruixin ⋅ 05/22 ⋅ 0

IDEA使用sonarLint

一、IDEA如何安装SonarLint插件 1.打开 Idea 2.点击【File】 3.点击【Settings】 4.点击【Plugins】 5.在搜索栏中输入“sonarlint”关键字 6.点击【Install】进行安装 7.重启Idea 二、IDEA如...

开源中国成都区源花 ⋅ 今天 ⋅ 0

idea 将普通java工程转为maven

1.在idea打开工程,右击工程,选择add framework support 选择maven 2.关闭工程 打开工程根目录,将 .idea 文件夹删除重新导入idea 就会和直接构建的maven工程目录结构一致了。...

jag623 ⋅ 05/16 ⋅ 0

Linux开发环境搭建之Intellij Idea安装配置

本文将会在Linux环境下安装使用Intellij Idea开发工具,然后在Idea中配置Maven和Tomcat,如果还没有Maven环境,可以参考《Linux开发环境搭建之Maven安装配置 》一文。 一、环境准备 1.Linxu桌...

MaxBill ⋅ 05/14 ⋅ 0

Windows + IDEA + SBT 打造Spark源码阅读环境

http://guozhongxin.com/pages/2014/10/15/sparksourcecode.html Spark源码阅读环境的准备 Spark源码是有Scala语言写成的,目前,IDEA对Scala的支持要比eclipse要好,大多数人会选在在IDEA上...

chenhao_asd ⋅ 04/25 ⋅ 0

IntelliJ IDEA 2018.2 EAP 发布,支持 Touch Bar

IntelliJ IDEA 2018.2 EAP 已发布:包含对 MacBook Touch Bar 的支持,对 Gradle 支持的改进,新图标,Spring Boot 及一些更新。 支持 Touch Bar 即将推出的 IntelliJ IDEA 2018.2 引入了 To...

达尔文 ⋅ 05/18 ⋅ 0

集成开发工具 Android Studio 3.2 Canary 13 发布

Android Studio 3.2 Canary 13 已经发布在 Canary 和 Dev 频道。 Android Studio 是一个 Android 集成开发工具,基于 IntelliJ IDEA,类似 Eclipse ADT,Android Studio 提供了集成的 Androi...

雨田桑 ⋅ 05/01 ⋅ 0

idea下搭建SSM框架后无法访问webapp下的jsp也无法访问controller中的方法

如题所述,我在idea上搭好了SSM后tomcat可以正常显示欢迎界面但是我既无法访问controller中的方法,也无法访问webapp下的jsp页面,网上查了好久都没有找到原因,他们的解决方法也不适用在我这...

SurpaX ⋅ 04/12 ⋅ 0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

彻底删除Microsoft Office的方法

参照此链接彻底删除Office https://support.office.com/zh-cn/article/%e4%bb%8e-pc-%e5%8d%b8%e8%bd%bd-office-9dd49b83-264a-477a-8fcc-2fdf5dbf61d8?ui=zh-CN&rs=zh-CN&ad=CN......

Kampfer ⋅ 29分钟前 ⋅ 0

大盘与个股之间关系

大盘走多:积极出手 顺势加码 大盘走空: 少量出手 退场观望 大盘做头:逆势减码 少量操作 大盘做底 : 小量建仓 小量试单

guozenhua ⋅ 31分钟前 ⋅ 0

Day16 LVM(逻辑卷管理)与磁盘故障小案例

lvm详解 简述 LVM的产生是因为传统的分区一旦分区好后就无法在线扩充空间,也存在一些工具能实现在线扩充空间但是还是会面临数据损坏的风险;传统的分区当分区空间不足时,一般的解决办法是再...

杉下 ⋅ 38分钟前 ⋅ 0

rsync实现多台linux服务器的文件同步

一、首先安装rsync,怎样安装都行,rpm,yum,还是你用源码安装都可以。因为我用的是阿里云的ESC,yum install rsync就ok了。 二、配置rsync服务 1.先建立个同步数据的帐号 123 groupadd r...

在下头真的很硬 ⋅ 51分钟前 ⋅ 0

前端基础(三):函数

字数:1685 阅读时间:5分钟 函数定义 在最新的ES规范中,声明函数有4中方法: -函数声明 -函数表达式 -构造函数Function -生成器函数 1.函数声明 语法: function name([param[, param2 [....

老司机带你撸代码 ⋅ 今天 ⋅ 0

Java虚拟机的Heap监狱

在Java虚拟机中,我是一个位高权重的大管家,他们都很怕我,尤其是那些Java 对象,我把他们圈到一个叫做Heap的“监狱”里,严格管理,生杀大权尽在掌握。 中国人把Stack翻译成“栈”,把Hea...

java高级架构牛人 ⋅ 今天 ⋅ 0

Spring MVC基本概念

只写Controller

颖伙虫 ⋅ 今天 ⋅ 0

微软重金收购GitHub的背后逻辑原来是这样的

全球最大的开发者社区GitHub网站花落谁家的问题已经敲定,微软最终以75亿美元迎娶了这位在外界看来无比“神秘”的小家碧玉。尽管此事已过去一些时日,但整个开发者世界,包括全球各地的开源社...

linux-tao ⋅ 今天 ⋅ 0

磁盘管理—逻辑卷lvm

4.10-4.12 lvm 操作流程: 磁盘分区-->创建物理卷-->划分为卷组-->划分成逻辑卷-->格式化、挂载-->扩容。 磁盘分区 注: 创建分区时需要更改其文件类型为lvm(代码8e) 分区 3 已设置为 Linu...

弓正 ⋅ 今天 ⋅ 0

Spring源码解析(六)——实例创建(上)

前言 经过前期所有的准备工作,Spring已经获取到需要创建实例的 beanName 和对应创建所需要信息 BeanDefinition,接下来就是实例创建的过程,由于该过程涉及到大量源码,所以将分为多个章节进...

MarvelCode ⋅ 今天 ⋅ 0

没有更多内容

加载失败,请刷新页面

加载更多

下一页

返回顶部
顶部