Ajax登录

 
 
<! 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 >
< link href = "css/style.css" rel = "stylesheet" type = "text/css" />
< script language = "JavaScript" src = "js/jquery.js" ></ script >
< script src = "js/cloud.js" type = "text/javascript" ></ script >
< script language = "javascript" >
$ ( function (){
$ ( ' . loginbox ' ). css ({ ' position ':' absolute ',' left ' :( $ ( window ). width ()- 692 )/ 2 });
$ ( window ). resize ( function (){
$ ( ' . loginbox ' ). css ({ ' position ':' absolute ',' left ' :( $ ( window ). width ()- 692 )/ 2 });
})
});
</ script >
</ head >
< body style = "background-color:#df7611; background-image:url(images/light.png); background-repeat:no-repeat; background-position:center top; overflow:hidden;" >
< div id = "mainBody" >
< div id = "cloud1" class =" cloud "></div>
<div id=" cloud2 " class=" cloud "></div>
</div>
<div class=" logintop ">
<span>欢迎登录后台管理界面平台</span>
<ul>
<li><a href=" # ">回首页</a></li>
<li><a href=" # ">帮助</a></li>
<li><a href=" # ">关于</a></li>
</ul>
</div>
<div class=" loginbody ">
<span class=" systemlogo "></span>
<div class=" loginbox ">
<ul>
<li><input name="" type=" text " class=" loginuser " value=" admin " οnclick=" JavaScript: this . value = '' "/></li>
<li><input name="" type=" text " class=" loginpwd " value=" 密码 " οnclick=" JavaScript: this . value = '' "/></li>
<li><input name="" type=" button " class=" loginbtn " value=" 登录 " οnclick=" javascript: window . location = ' main . html ' " /><label><input name="" type=" checkbox " value="" checked=" checked " />记住密码</label><label><a href=" # ">忘记密码?</a></label></li>
</ul>
</div>
</div>
<div class=" loginbm ">版权所有 2014 <a href=" http: //www.uimaker.com">uimaker.com</a> 仅供学习交流,勿用于任何商业用途</div>
</ body >
</ html >
****************************************************************************************************************
js 页面
var xmlhttp ;
function getload ()
{
document . getElementById ( "loginname" ). focus ();
}
function getIE ()
{
if ( window . XMLHttpRequest )
{
xmlhttp = new XMLHttpRequest ();
}
else
{
xmlhttp = new ActiveObject ( "Microsoft.XMLHTTP" );
}
}
function loginname ( obj )
{
getIE ();
var name = obj . value ;
if ( name . length == 0 )
{
document . getElementById ( "nameflag" ). innerHTML = "<font color=red></font>" ;
document . getElementById ( "Loginbtn" ). style . visibility = "hidden" ;
}
else
{
var url = "${pageContext.request.contextPath}/emp_myname.action?name=" + name ;
var myurl = encodeURI ( url );
xmlhttp . open ( "post" , myurl , true );
xmlhttp . send ();
xmlhttp . onreadystatechange = getBack ;
}
}
function getBack ()
{
if ( xmlhttp . readyState == 4 && xmlhttp . status == 200 )
{
if ( xmlhttp . responseText == 1 )
{
document . getElementById ( "nameflag" ). innerHTML = "" ;
document . getElementById ( "Loginbtn" ). style . visibility = "visible" ;
}
else
{
document . getElementById ( "nameflag" ). innerHTML = "<font color=red></font>" ;
document . getElementById ( "Loginbtn" ). style . visibility = "hidden" ;
}
}
}
function login (){
getIE ();
var name = document . getElementById ( "loginname" ). value ;
var psw = document . getElementById ( "loginpsw" ). value ;
if ( name . length == 0 ){
document . getElementById ( "nameflag" ). innerHTML = "<font color=red></font>" ;
} else if ( psw . length == 0 ){
alert ( "瀵嗙爜涓嶈兘涓虹┖" );
} else {
var url = encodeURI ( "${pageContext.request.contextPath}/emp_getlogin.action?name=" + name + "&" + "psw=" + psw );
xmlhttp . open ( "post" , url , true );
xmlhttp . send ();
xmlhttp . onreadystatechange = loginback ;
}
}
//回滚
function loginback (){
if ( xmlhttp . readyState == 4 && xmlhttp . status == 200 ) {
if ( xmlhttp . responseText == 1 ){
window . location . href = "./main.jsp" ;
} else {
document . getElementById ( "xx" ). innerHTML = "<font color=red></font>" ;
return false ;
}
}
}
*********************************************************************************************
Action
//获得登录名
public String myname ()
{
int result = 0 ;
try
{
String myname = new String ( name . getBytes ( "ISO8859_1" ), "utf-8" );
int t = this . empService . getLoginName ( myname );
HttpServletResponse response = ServletActionContext . getResponse ();
response . setContentType ( "text/html;charset=UTF-8" );
PrintWriter out = response . getWriter ();
if ( t > 0 )
{
result = 1 ;
}
else
{
result = 0 ;
}
out . println ( result );
out . flush ();
out . close ();
}
catch ( Exception e )
{
e . printStackTrace ();
}
return null ;
}
//登录
public String getlogin (){
int result = 0 ;
try {
String myname = new String ( this . name . getBytes ( "ISO8859_1" ), "utf-8" );
String mypsw = new String ( this . psw . getBytes ( "ISO8859_1" ), "utf-8" );
TEmp e = new TEmp ();
e . setELoginname ( myname );
e . setEPsw ( mypsw );
int t = this . empService . getLogin ( e );
HttpServletResponse response = ServletActionContext . getResponse ();
response . setContentType ( "text/html;charset=UTF-8" );
PrintWriter out = response . getWriter ();
if ( t > 0 )
{
result = 1 ;
}
else
{
result = 0 ;
}
out . println ( result );
out . flush ();
out . close ();
} catch ( Exception e ) {
e . printStackTrace ();
}
return null ;
}
******************************************************************************************* \
Dao
//得到登录名字
public int getLoginName ( String name ){
List ar = getHibernateTemplate (). find ( "from TEmp where ELoginname = ?" , name );
return ar . size ();
}
//登录查询
public List getLoginCount ( final TEmp emp ) {
return getHibernateTemplate (). executeFind ( new HibernateCallback () {
public Object doInHibernate ( Session session )
throws HibernateException , SQLException {
List ar = session . createQuery ( " from TEmp t where t.ELoginname = ? and t.EPsw =?" ). setString ( 0 , emp . getELoginname ()). setString ( 1 , emp . getEPsw ()). list ();
return ar ;
}
});
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值