之前一直想sso接口已经写好了,登录注册功能是怎么调用的呢?原来在登录注册的jsp页面实现的接口的调用,页面的校验和验证功能在jsp页面即可实现。
注册页面:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<!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="pragma" content="no-cache"><meta http-equiv="Cache-Control" content="no-cache,must-revalidate"><title>注册-个人用户</title><link type="text/css" rel="stylesheet" href="/css/regist.personal.css"/><link type="text/css" rel="stylesheet" href="/css/passport.base.css"/><script type="text/javascript" src="/js/jquery-1.6.4.js"></script>
</head>
<body>
<div class="w" id="logo"><div><a href="http://localhost:8082"><img src="/images/taotao-logo.gif" alt="淘淘商城" width="170" height="60"/></a> <b></b></div>
</div><div class="w" id="regist"><div class="mt"><ul class="tab"><li class="curr">个人用户</li></ul><div class="extra"><span>我已经注册,现在就 <a href="/page/login" class="flk13">登录</a></span></div></div><div class="mc"><form id="personRegForm" method="post" οnsubmit="return false;"><div class="form" onselectstart="return false;"><div class="item" id="select-regName"><span class="label"><b class="ftx04">*</b>用户名:</span><div class="fl item-ifo"><div class="o-intelligent-regName"><input type="text" id="regName" name="username" class="text" tabindex="1" autoComplete="off"οnpaste="return false;"value=""οnfοcus="if(this.value=='') this.value='';this.style.color='#333'"οnblur="if(this.value=='') {this.value='';this.style.color='#999999'}"/><i class="i-name"></i><ul id="intelligent-regName" class="hide"></ul><label id="regName_succeed" class="blank"></label><label id="regName_error" class="hide"></label></div></div></div><div id="o-password"><div class="item"><span class="label"><b class="ftx04">*</b>请设置密码:</span><div class="fl item-ifo"><input type="password" id="pwd" name="password" class="text" tabindex="2"style="ime-mode:disabled;"οnpaste="return false" autocomplete="off"/><i class="i-pass"></i><label id="pwd_succeed" class="blank"></label><label id="pwd_error"></label><span class="clr"></span></div></div><div class="item"><span class="label"><b class="ftx04">*</b>请确认密码:</span><div class="fl item-ifo"><input type="password" id="pwdRepeat" name="pwdRepeat" class="text" tabindex="3"οnpaste="return false" autocomplete="off"/><i class="i-pass"></i><label id="pwdRepeat_succeed" class="blank"></label><label id="pwdRepeat_error"></label></div></div><div class="item" id="dphone"><span class="label"><b class="ftx04">*</b>验证手机:</span><div class="fl item-ifo"><input type="text" id="phone" maxlength="11" name="phone"class="text" tabindex="4"autocomplete="off" /> <i class="i-phone"></i> <labelid="phone_succeed" class="blank"></label> <labelid="phone_error"></label></div></div></div><div class="item item-new"><span class="label"> </span><div class="fl item-ifo"><input type="checkbox" class="checkbox" checked="checked" id="readme"οnclick="agreeonProtocol();"><label for="protocol">我已阅读并同意<a href="#" class="blue" id="protocol">《淘淘用户注册协议》</a></label><span class="clr"></span><label id="protocol_error" class="error hide">请接受服务条款</label></div></div><div class="item"><span class="label"> </span><input type="button" class="btn-img btn-regist" id="registsubmit" value="立即注册" tabindex="8"clstag="regist|keycount|personalreg|07"οnclick="REGISTER.reg();"/></div></div><div class="phone"><img width="180" height="180" src="/images/phone-bg.jpg"></div><span class="clr"></span></form></div>
<script type="text/javascript">var REGISTER={param:{//单点登录系统的urlsurl:""},inputcheck:function(){//不能为空检查if ($("#regName").val() == "") {alert("用户名不能为空");$("#regName").focus();return false;}if ($("#pwd").val() == "") {alert("密码不能为空");$("#pwd").focus();return false;}if ($("#phone").val() == "") {alert("手机号不能为空");$("#phone").focus();return false;}//密码检查if ($("#pwd").val() != $("#pwdRepeat").val()) {alert("确认密码和密码不一致,请重新输入!");$("#pwdRepeat").select();$("#pwdRepeat").focus();return false;}return true;},beforeSubmit:function() {//检查用户是否已经被占用$.ajax({
//这是校验的接口调用,通过接口中的url来实现的url : REGISTER.param.surl + "/user/check/"+escape($("#regName").val())+"/1?r=" + Math.random(),success : function(data) {if (data.data) {//检查手机号是否存在$.ajax({url : REGISTER.param.surl + "/user/check/"+$("#phone").val()+"/2?r=" + Math.random(),success : function(data) {if (data.data) {REGISTER.doSubmit();} else {alert("此手机号已经被注册!");$("#phone").select();}}});} else {alert("此用户名已经被占用,请选择其他用户名");$("#regName").select();} }});},doSubmit:function() {
//这是注册的接口,通过注册接口的URL来实现的调用$.post("/user/register",$("#personRegForm").serialize(), function(data){if(data.status == 200){alert('用户注册成功,请登录!');REGISTER.login();} else {alert("注册失败!");}});},login:function() {location.href = "/page/login";return false;},reg:function() {if (this.inputcheck()) {this.beforeSubmit();}}};
</script>
</body>
</html>
登录页面
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page trimDirectiveWhitespaces="true" %>
<!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=gb2312"/><title>登录淘淘</title><link type="text/css" rel="stylesheet" href="/css/login.css"/><script type="text/javascript" src="/js/jquery-1.6.4.js"></script>
</head>
<body>
<div class="w"><div id="logo"><a href="http://localhost:8082" clstag="passport|keycount|login|01"><img src="/images/taotao-logo.gif" alt="淘淘" width="170" height="60"/></a><b></b></div>
</div>
<form id="formlogin" method="post" οnsubmit="return false;"><div class=" w1" id="entry"><div class="mc " id="bgDiv"><div id="entry-bg" clstag="passport|keycount|login|02" style="width: 511px; height: 455px; position: absolute; left: -44px; top: -44px; background: url(/images/544a11d3Na5a3d566.png) 0px 0px no-repeat;"></div><div class="form "><div class="item fore1"><span>用户名</span><div class="item-ifo"><input type="text" id="loginname" name="username" class="text" tabindex="1" autocomplete="off"/><div class="i-name ico"></div><label id="loginname_succeed" class="blank invisible"></label><label id="loginname_error" class="hide"><b></b></label></div></div><script type="text/javascript">setTimeout(function () {if (!$("#loginname").val()) {$("#loginname").get(0).focus();}}, 0);</script><div id="capslock"><i></i><s></s>键盘大写锁定已打开,请注意大小写</div><div class="item fore2"><span>密码</span><div class="item-ifo"><input type="password" id="nloginpwd" name="password" class="text" tabindex="2" autocomplete="off"/><div class="i-pass ico"></div><label id="loginpwd_succeed" class="blank invisible"></label><label id="loginpwd_error" class="hide"></label></div></div><div class="item login-btn2013"><input type="button" class="btn-img btn-entry" id="loginsubmit" value="登录" tabindex="8" clstag="passport|keycount|login|06"/></div></div></div><div class="free-regist"><span><a href="/page/register" clstag="passport|keycount|login|08">免费注册>></a></span></div></div>
</form>
<script type="text/javascript">var redirectUrl = "${redirect}";var LOGIN = {checkInput:function() {if ($("#loginname").val() == "") {alert("用户名不能为空");$("#loginname").focus();return false;}if ($("#nloginpwd").val() == "") {alert("密码不能为空");$("#nloginpwd").focus();return false;}return true;},doLogin:function() {
//这里是一样的功能,调用登录的接口来实现的
$.post("/user/login", $("#formlogin").serialize(),function(data){if (data.status == 200) {alert("登录成功!");if (redirectUrl == "") {location.href = "http://localhost:8082";} else {location.href = redirectUrl;}} else {alert("登录失败,原因是:" + data.msg);$("#loginname").select();}});},login:function() {if (this.checkInput()) {this.doLogin();}}};$(function(){$("#loginsubmit").click(function(){LOGIN.login();});});
</script>
</body>
</html>