注册和登录页面:
注册页面代码如下:
要求实现非空验证,当注册时输入用户名时,判断用户名是否存在,如存在则提示,不存在,可注册,将信息插入数据库
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<script type="text/javascript" src="<%=request.getContextPath()%>/js/jquery-1.12.4.js"></script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'login.jsp' starting page</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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<script type="text/javascript">
function nameLeave(){
var path="<%=request.getContextPath() %>";
var uname=$("#uname").val();
if(uname==null ||uname==""){
$("#nameid").html("用户名不能为空!");
}else{
$.post(
"jsp/Test.jsp",
{
"uname":uname},
function(result){
$("#nameid").html(result);
});
}
}
function pwdLeave(){
var pwd=$("#pwd").val();
if(pwd==null ||pwd==""){
$("#pwdid").html("密码不能为空!");
}else{
$("#pwdid").html("");
}
}
</script>
</head>
<body>
<form action="<%=request.getContextPath() %>/servlet/LoginServlet" method="post">
<table >
<tr>
<td>用户名:</

本文介绍如何在页面上创建简单的注册和登录功能,并利用Ajax进行非空验证和错误检查。注册时,通过Ajax检查用户名是否已存在,确保唯一性;登录时,验证用户信息并连接数据库,成功后跳转至欢迎页面。
最低0.47元/天 解锁文章
5505

被折叠的 条评论
为什么被折叠?



