JavaWeb网上图书商城完整项目--day02-14.登录功能的login页面处理

1、现在注册成功之后,我们来到登录页面,登录页面在于

 

在登录页面。我们也需要向注册页面一样对登录的用户名、密码 验证码等在jsp页面中进行校验,校验我们单独放置一个login.js文件中进行处理,然后login.jsp加载该js文件

 

我们来看看login.js的代码和regist.js的代码一样,这里就不用花太多时间进行介绍

$(function() {/** 1. 让登录按钮在得到和失去焦点时切换图片*/$("#submit").hover(function() {$("#submit").attr("src", "/goods/images/login2.jpg");},function() {$("#submit").attr("src", "/goods/images/login1.jpg");});/** 2. 给注册按钮添加submit()事件,完成表单校验*/$("#submit").submit(function(){$("#msg").text("");var bool = true;$(".input").each(function() {var inputName = $(this).attr("name");if(!invokeValidateFunction(inputName)) {bool = false;}});return bool;});/** 3. 输入框得到焦点时隐藏错误信息*/$(".input").focus(function() {var inputName = $(this).attr("name");$("#" + inputName + "Error").css("display", "none");});/** 4. 输入框推动焦点时进行校验*/$(".input").blur(function() {var inputName = $(this).attr("name");invokeValidateFunction(inputName);})
});/** 输入input名称,调用对应的validate方法。* 例如input名称为:loginname,那么调用validateLoginname()方法。*/
function invokeValidateFunction(inputName) {inputName = inputName.substring(0, 1).toUpperCase() + inputName.substring(1);var functionName = "validate" + inputName;return eval(functionName + "()");    
}/** 校验登录名*/
function validateLoginname() {var bool = true;$("#loginnameError").css("display", "none");var value = $("#loginname").val();if(!value) {// 非空校验$("#loginnameError").css("display", "");$("#loginnameError").text("用户名不能为空!");bool = false;} else if(value.length < 3 || value.length > 20) {//长度校验$("#loginnameError").css("display", "");$("#loginnameError").text("用户名长度必须在3 ~ 20之间!");bool = false;}return bool;
}/** 校验密码*/
function validateLoginpass() {var bool = true;$("#loginpassError").css("display", "none");var value = $("#loginpass").val();if(!value) {// 非空校验$("#loginpassError").css("display", "");$("#loginpassError").text("密码不能为空!");bool = false;} else if(value.length < 3 || value.length > 20) {//长度校验$("#loginpassError").css("display", "");$("#loginpassError").text("密码长度必须在3 ~ 20之间!");bool = false;}return bool;
}/** 校验验证码*/
function validateVerifyCode() {var bool = true;$("#verifyCodeError").css("display", "none");var value = $("#verifyCode").val();if(!value) {//非空校验$("#verifyCodeError").css("display", "");$("#verifyCodeError").text("验证码不能为空!");bool = false;} else if(value.length != 4) {//长度不为4就是错误的$("#verifyCodeError").css("display", "");$("#verifyCodeError").text("错误的验证码!");bool = false;} else {//验证码是否正确
        $.ajax({cache: false,async: false,type: "POST",dataType: "json",data: {method: "validateVerifyCode", verifyCode: value},url: "/goods/UserServlet",success: function(flag) {if(!flag) {$("#verifyCodeError").css("display", "");$("#verifyCodeError").text("错误的验证码!");bool = false;                    }}});}return bool;
}

我们来看login.jsp的代码

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html><head><title>登录</title><meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0">    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><meta http-equiv="content-type" content="text/html;charset=utf-8"><!--<link rel="stylesheet" type="text/css" href="styles.css">--><link rel="stylesheet" type="text/css" href="<c:url value='/jsps/css/user/login.css'/>"><script type="text/javascript" src="<c:url value='/jquery/jquery-1.5.1.js'/>"></script><script src="<c:url value='/js/common.js'/>"></script><!-- 引入login.js文件 --><script type="text/javascript" src="<c:url value='/jsps/js/user/login.js'/>"></script></head><body><div class="main"><div><img src="<c:url value='/images/logo.gif'/>" /></div><div><div class="imageDiv"><img class="img" src="<c:url value='/images/zj.png'/>"/></div><div class="login1"><div class="login2"><div class="loginTopDiv"><span class="loginTop">传智会员登录</span><span><a href="<c:url value='/jsps/user/regist.jsp'/>" class="registBtn"></a></span></div><div><form target="_top" action="<c:url value='/index.jsp'/>" method="post" id="loginForm"><input type="hidden" name="method" value="" /><table><tr><td width="50"></td><td><label class="error" id="msg"></label></td></tr><tr><td width="50">用户名</td><td><input class="input" type="text" name="loginname" id="loginname"/></td></tr><tr><td height="20">&nbsp;</td><td><label id="loginnameError" class="error"></label></td></tr><tr><td>密 码</td><td><input class="input" type="password" name="loginpass" id="loginpass"/></td></tr><tr><td height="20">&nbsp;</td><td><label id="loginpassError" class="error"></label></td></tr><tr><td>验证码</td><td><input class="input yzm" type="text" name="verifyCode" id="verifyCode" value=""/><img id="vCode" src="<c:url value='/VerifyCodeServlet'/>"/><a id="verifyCode">换张图</a></td></tr><tr><td height="20px">&nbsp;</td><td><label id="verifyCodeError" class="error"></label></td></tr><tr><td>&nbsp;</td><td align="left"><input type="image" id="submit" src="<c:url value='/images/login1.jpg'/>" class="loginBtn"/></td></tr>                                                                                </table></form></div></div></div></div></div></body>
</html>

我们来看程序运行的效果:

 

转载于:https://www.cnblogs.com/kebibuluan/p/6848208.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/541386.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

php多线程是什么意思,多线程是什么意思

线程是操作系统能够进行运算调度的最小单位&#xff0c;它被包含在进程之中&#xff0c;是进程中的实际运作单位&#xff0c;而多线程就是指从软件或者硬件上实现多个线程并发执行的技术&#xff0c;具有多线程能力的计算机因有硬件支持而能够在同一时间执行多于一个线程&#…

c++一个类创建多个对象_C ++ | 创建一个类的多个对象

c一个类创建多个对象In the below program, we are creating a C program to create multiple objects of a class. 在下面的程序中&#xff0c;我们正在创建一个C 程序来创建一个类的多个对象 。 /* C program to create multiple objects of a class */#include <iostrea…

Activity中与ListActivity中使用listview区别

一.Activity中与ListActivity中使用listview区别&#xff08;本身没多大区别&#xff0c;只是ListActivity在listview的显示上做了一些优化&#xff09;Activity中使用Listview步骤&#xff1a;1.xml布局中,ListView标签id可以任意取值如&#xff1a;<ListView andro…

java相关是什么,什么是java

java基础常见面试题&#xff0c;这是一篇超长的随笔&#xff01;&#xff01;&#xff01;1. Java基础部分....................................................... 4 1、一个".java"源文件中是否可以包括多个类(不是内部类)&#xff1f;有什么限制&#xff1f;.. …

如何在Scala中将Double转换为String?

Double in Scala is a data type that stores numerical values that have decimals. It can store a 64-bit floating point number. Scala中的Double是一种数据类型&#xff0c;用于存储带有小数的数值。 它可以存储一个64位浮点数。 Example: 例&#xff1a; val decimal…

basic knowledge

Position 属性&#xff1a;规定元素的定位类型。即元素脱离文档流的布局&#xff0c;在页面的任意位置显示。 ①absolute &#xff1a;绝对定位&#xff1b;脱离文档流的布局&#xff0c;遗留下来的空间由后面的元素填充。定位的起始位置为最近的父元素(postion不为static)&…

avatar.php uid,phpcms函数库中获取会员头像方法get_memberavatar()有时无效问题

修复方法&#xff1a;首先我先给出无效情况的演示代码&#xff0c;如下&#xff1a;$userid intval($_GET[userid]);$userinfo $this->db->get_one(userid.$userid);$this->db->set_model(10); //原因便在这里$userdetail $this->db->get_one("useri…

ruby 集合 分组_将Ruby中两个集合的所有元素结合在一起

ruby 集合 分组In this program, we will see how we can combine the two sets? This is not a very difficult task. This can be easily done with the help of the operator. In many places of programming, you will find that operator is overloaded for various ty…

​Python中面向对象的编程

Python面向对象的编程1概述&#xff08;1&#xff09;面向对象编程面向对象的编程是利用“类”和“对象”来创建各种模型来实现对真实世界的描述&#xff0c;使用面向对象编程的原因一方面是因为它可以使程序的维护和扩展变得更简单&#xff0c;并且可以大大提高程序开发效率&a…

php中用for循环制作矩形,PHP中for循环语句的几种变型

PHP中for循环语句的几种变型2021-01-22 10:21:42406for语句可以说是PHP(同时也是多种语言)的循环控制部份最基本的一个语句了&#xff0c;for语句的执行规律和基础用法在这里就不多说&#xff0c;可以参见PHP手册for语句部分。PHP手册中对它的语法定义如下&#xff1a;for(expr…

c语言用命令行编译运行程序_使用C程序执行系统命令

c语言用命令行编译运行程序Sometimes, we may need to execute Linux/Windows DOS commands through our C program. (Note: the code given below is compiled and executed on Linux GCC compiler, so here we are testing Linux commands only). 有时&#xff0c;我们可能需…

python 熊猫,Python熊猫

我试图连续分组和计算相同的信息&#xff1a;#Functionsdef postal_saude ():global df, lista_solic#List of solicitantes in Postal Saudelist_sol [lista_solic["name1"], lista_solic["name2"]]#filter Postal Saude Solicitantesdf df[(df[Cliente…

Spring的两种任务调度Scheduled和Async

Spring提供了两种后台任务的方法,分别是: 调度任务&#xff0c;Schedule异步任务&#xff0c;Async当然&#xff0c;使用这两个是有条件的&#xff0c;需要在spring应用的上下文中声明<task:annotation-driven/>当然&#xff0c;如果我们是基于java配置的&#xff0c;需要…

建立单链表 单链表的插入_单链列表插入

建立单链表 单链表的插入All possible cases: 所有可能的情况&#xff1a; Inserting at beginning 开始插入 Inserting at the ending 在末尾插入 Inserting at given position 在给定位置插入 Algorithms: 算法&#xff1a; 1)开始插入 (1) Inserting at the beginning) In…

mysql学习笔记(1-安装简介)

mysql的安装方式&#xff1a;(1)通过系统提供的默认版本(rpm包&#xff0c;稳定版&#xff0c;该版本满足了使用的需求&#xff0c;建议使用&#xff0c;os vendor)(2)mysql官方提供官方提供的通用rpm安装包通用二进制格式的程序包(直接下载文件&#xff0c;解压到指定目录&…

存储器间接寻址方式_8086中的数据存储器寻址模式

存储器间接寻址方式In this type of addressing mode, first the offset address is calculated, then the memory address is calculated and then the operand form that memory location is fetched. There are following modes which lie under the Data Addressing Mode: …

oracle asm 删除diskgroup,ASM磁盘组删除DISK操作

没想到这么简单的操作&#xff0c;由于不熟悉还碰到了两个小问题。[oracledbserver1 ~]$ sqlplus / as sysdbaSQL*Plus: Release 11.2.0.2.0 Production on Tue Aug 9 10:08:062011Copyright (c) 1982, 2010, Oracle.All rights reserved.Connected to:Oracle Database 11g Ent…

intellij idea 最常用的快捷键

F2&#xff0c; 可以快速的向下跳走 CtrlF7&#xff0c;可以查询当前元素在当前文件中的引用&#xff0c;然后按 F3 可以选择AltQ&#xff0c;可以看到当前方法的声明CtrlP&#xff0c;可以显示参数信息CtrlAltV&#xff0c;可以引入变量。例如&#xff1a;new String(); 自动导…

如何在Java中检查字符串是否为数字?

We will check whether string is a number or not – with the help of logic we will solve this problem, 我们将检查字符串是否为数字-借助逻辑&#xff0c;我们将解决此问题&#xff0c; In the first step, we will take a string variable named str and store any val…

oracle清理告警日志,Oracle 跟踪/告警/监听日志的清理脚本

[root ~]# cat del_oracle_log.sh#!/bin/bashsource /home/oracle/.bash_profilefunction audit_log(){ #---audit_log日志跟踪文件#audit_log$(strings $ORACLE_HOME/dbs/spfile$ORACLE_SID.ora|grep -i audit_file_dest|awk -F {print $NF}|sed "s///g")audit_lo…