设为首页 加入收藏

TOP

基于SSH框架下登录验证码模块的实现(一)
2018-03-02 06:57:06 】 浏览:684
Tags:基于 SSH 框架 登录 验证 模块 实现

记录基于SSH框架下登录验证码模块的实现过程步骤。


1、前端页面代码:


主要以jQuery的ajax异步请求实现。


...
<script type="text/java script" src="${pageContext.request.contextPath }/js/jquery-1.11.3.min.js"></script>
<script type="text/java script">
    $(function () {
        //验证码图片刷新
        $("#vcode").click(function () {
            $(this).prop("src","${pageContext.request.contextPath }/user_createVerificationCode?"+new Date());


        });
        //验证码校验
        $("#txtcode").blur(function () {
            var url = "${pageContext.request.contextPath }/user_checkVerificationCode"
            var code = $(this).val();
            $.get(url,{"code":code},function (result) {
                if(result != ""){
                    $("#tip").html(result);
                    //验证码错误,登录按钮失效
                    $("#btn").prop("disabled","disabled");
                }else{
                    $("#tip").html("");
                    $("#btn").removeAttr("disabled");
                }
            });
        });
    })
</script>
...
<tr>
    <td style="HEIGHT: 28px">验证码:</td>
    <td style="HEIGHT: 28px"><input id=txtcode style="WIDTH: 130px" name=txtcode required></td>
    <td style="HEIGHT: 18px"><img id="vcode"  src="${pageContext.request.contextPath }/user_createVerificationCode" /></td>
    <td style="HEIGHT: 28px">&nbsp;<span id="tip" style="color: red"></span></td>
<tr>
    <td></td>
    <td>
        <input id="btn" value="登录">
    </td>
</tr>
...


2、struts.xml


<package name="user" extends="struts-default" namespace="/">
    <action name="user_*" class="userAction" method="{1}"></action>
</package>


3、applicationContext.xml


<bean id="userAction" class="com.pri.web.action.UserAction" scope="prototype">
        <property name="validateCode" ref="validateCode"/>
</bean>
<!-- 生成验证图片需要为多例,默认情况为单例 -->
<bean id="validateCode" class="cn.dsna.util.images.ValidateCode" scope="prototy

首页 上一页 1 2 3 4 下一页 尾页 1/4/4
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇基于注解的简单SSH保存用户小案例 下一篇关于 C++ 日期 & 时间 初入门

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目