找回密码
 注册
搜索
热搜: 回贴
  • 前程无忧官网首页 有什么好的平台可以
  • 最新的销售平台 互联网营销的平台有哪
  • 制作网页的基本流程 网页制作和网页设
  • 【帝国CMS】输出带序号的列表(数字排
  • 网站建设公司 三一,中联,极东泵车的
  • 织梦 建站 织梦网站模版后台怎么更改
  • 云服务官网 哪些网站有免费的简历模板
  • 如何建网站要什么条件 建网站要用什么
  • 吉林市移动公司电话 吉林省退休人员网
  • 设计类毕业论文 网站设计与实现毕业论
查看: 6908|回复: 1

jsp学习笔记7

[复制链接]
发表于 2009-11-29 02:04:47 | 显示全部楼层 |阅读模式 IP:江苏扬州
ajax用户验证(jsp)
index.html
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage=""%>
<%
request.setCharacterEncoding("utf-8");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="ajax.js">
</script>
</head>
<body>
AJAX:
<form action="greeting.jsp" method="get">
<p>
    <input type="text" id="name" name="name" value="" onblur="startRequest()"/>
    <span id="show1">*</span></p>
<p>
    <input type="text" id="pwd" name="pwd" value="" onblur="spwd()"/>
    <span id="pwdshow">*</span></p>
    <p>
<input type="text" id="repwd" name="repwd" value="" onblur="srepwd()" />
<span id="repwdshow">*</span>
</p>
<p>
    <input type="button" value="简单请求" onclick="startRequest()" />
    <input type="submit" onclick="return checkform()" value="button" />
</p>
</form>
</body>
</html>
ajax.js

var xmlHttp;
function createXMLHttpRequest() {
if (window.ActiveXObject) {
   xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} else {
   if (window.XMLHttpRequest) {
    xmlHttp = new XMLHttpRequest();
   }
}
}
function startRequest() {
createXMLHttpRequest();
show("show1", "<img src='img/loading.gif'/>");                  //显示状态
xmlHttp.onreadystatechange = handleStateChange;
var name = document.getElementById("name").value;         ///////////////////////////////
xmlHttp.open("GET", "greeting.jsp?name=" + name, true);     //////////// get方法////////////
xmlHttp.send(null);                                     ///////////////////////////////
//xmlHttp.open("POST","greeting.jsp",true);                                             //////////////////////////////
//xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");         ///////////post方法///////////
//xmlHttp.send("name="+name);                                                           //////////////////////////////
}
function handleStateChange() {
if (xmlHttp.readyState == 4) {
   if (xmlHttp.status == 200) {
    var responseText = xmlHttp.responseText;
    show("show1", responseText);                 //调用show函数
   }
}
}
function show(span, obj) {                                  /////输出信息
var Show = document.getElementById(span);
Show.innerHTML = obj;
}
function checkform() {
if (document.getElementById("pwd").value == "") {
   document.getElementById("pwd").focus();
   show("pwdshow","密码不能为空");
   //document.getElementById("pwdshow").innerHTML="密码不能为空";
   return false;
}
if (document.getElementById("repwd").value == "") {
   document.getElementById("repwd").focus();
   show("repwdshow","请再次输入密码");
   return false;
}
if (document.getElementById("pwd").value != document.getElementById("repwd").value) {
   document.getElementById("repwd").focus();
   show("repwdshow","两次密码不一致");
   return false;
}
}
function spwd() {
if (document.getElementById("pwd").value == "") {
   //document.getElementById("pwd").focus();
   show("pwdshow","密码不能为空");
   return false;
} else {
   show("pwdshow", "OK!");
}
    //return true;
}
function srepwd() {
spwd();
if (document.getElementById("repwd").value == "") {
   //document.getElementById("repwd").focus();
   show("repwdshow","请再次输入密码");
   return false;
} else {
   show("repwdshow", "OK!");
}
    //return true;
if (document.getElementById("pwd").value != document.getElementById("repwd").value) {
   //document.getElementById("repwd").focus();
   show("repwdshow","两次密码不一致");
   return false;
} else {
   show("repwdshow", "OK!");
}
}
greeting.jsp
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage=""%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<%
request.setCharacterEncoding("utf-8");
String name=request.getParameter("name");
if(name.equals("123")){
//name="chongfu";
out.print("chongfu");
}else{
//name=name+"!!!!!";
out.print("hello,"+name);
}
%>
</body>
</html>
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-10-1 01:18 , Processed in 0.306337 second(s), 13 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表