<span style="font-size:18px;color:#ffffff;"><strong style="background-color: rgb(0, 0, 153);">登录页面(发送请求):index.jsp</strong></span>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'index.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<pre name="code" class="html"><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
System.out.println("有数据!");
out.print(1);
%>
type="text/javascript" src="js/jquery-1.8.3.js"></script> </head> <body> <div id="divMsg"> </div> <input type="text" id="userName"> <input type="text" id="userPass"> <input type="button" id="btn_1" value="点这个地方"> <a href="action.jsp">lll</a> </body></html><script type="text/javascript">//绑定全局ajaxStart事件$(function(){$("#divMsg").ajaxStart(function(){$(this).show().html("正在发送请求...");});});//绑定全局ajaxStop事件$(function(){$("#divMsg").ajaxStop(function(){$(this).show().html("请求完成...").hide();});});$("#btn_1").click(function(){//按钮事件alert("开始发送!");var $name=$("#userName");//用户名,用一个变量将对象现存起来,以后再次调用的时候,有助于加速代码执行var $pass=$("#userPass");//密码if($name.val()!=""&&$pass.val()!=""){UserLogin($name.val(),$pass.val());}else{if($name==""){alert("用户名不能为空!");$name.focus();return false;//如果不写,那么仍然会执行发送请求}else if($pass==""){alert("密码不能为空!");$pass.focus();return false;}}});function UserLogin(name,pass){//在传入的数据里面,加一个随机数:日期alert(name+pass);$.ajax({type:"GET",url:"action.jsp",data:"msg=wokao&msg2=wokaokao",dataType:"json",success:function(data){alert(data+"返回的数据:"+data);if(data=="1"||data==1){alert("验证成功!");}else{alert("验证失败!");return false;}}});}</script>
<strong><span style="font-size:24px;color:#ffffff;background-color: rgb(0, 0, 153);">响应action.jsp</span></strong>
<pre name="code" class="html"><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
System.out.println("有数据!");
out.print(1);
%>