<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
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 '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" src="js/checkLogin.js"></script>
-->
<script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
<script type="text/javascript" language="javascript" charset="UTF-8">
$(document)
.ready(
function() {
var name = $("#loginName");
name.blur(function() {
var text = name.val();
if (text == "") {
document.getElementById("span").innerHTML = "<p>用户名不能为空</p>";
return;
} else {
$
.post(
"checkLoginName.action?loginName="
+ text,
null,
function(result) {
var obj=eval("("+result+")");//解析JSON格式字符串
//alert(obj["result"]);//获取JSON字符串中的某一元素
//alert(result);
var json=JSON.parse(result);//解析JSON字符串
//alert(json.result);
if (json.result!=1) {
document
.getElementById("span").innerHTML = "<font color='green'>用户名可以用</font>";
} else {
document
.getElementById("span").innerHTML = "<font color='red'>用户名已存在</font>";
}
});
}
});
});
</script>
</head>
<body>
<div align="center" style="width: 100%;height: 100%">
<form action="loginAdmin" name="form1" method="post">
<table align="center">
<tr>
<td>用户名:</td>
<td id="t1"><input type="text" name="admin.loginName"
size="20px" id="loginName" />
<div id="span"></div></td>
</tr>
<tr>
<td>密 码:</td>
<td><input type="password" name="admin.loginPwd" size="20px" />
</td>
</tr>
<tr>
<td><input type="submit" value="登录" /></td>
<td><input type="button" value="注册" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>
Action层返回一个JSON格式的字符串,然后JSP页面解析出来就OK了。