Home >Web Front-end >JS Tutorial >jquery ajax 登录验证实现代码_jquery

jquery ajax 登录验证实现代码_jquery

WBOY
WBOYOriginal
2016-05-16 18:46:08995browse

使用 jquery 框架:下载 jquery.js
新建一个 web 工程 ajax ;
在 webRoot 下新建一个 jslib 文件夹:专门存放 js 文件;
在 webRoot 下新建一个 html/jsp 页面:
login.html

复制代码 代码如下:


在 jslib 下新建一个 js 文件:
verify.js ;
复制代码 代码如下:

function verify()
{
var paramObj=encodeURI(encodeURI($( "#username" ).val()));
$.get( "TestSvlt?username=" +paramObj, null ,callback);
}
function callback(data)
{
var resultObj=$( "#result" );
resultObj.html(data);
}

新建一个 servlet : AjaxLogin 类;在 doGet 方法中写
复制代码 代码如下:

response.setContentType( "text/html;charset=utf-8" );
PrintWriter out=response.getWriter();
String name=request.getParameter( "username" );
String username= URLDecoder.decode (name, "UTF-8" );
System. out .println(username);
if ( null ==username|| "" .equals(username))
{
out.print( "username is not null" );
}
else
{
if (! "lej" .equals(username))
{
out.print(username+ " not existing" );
}
else {
out.print(username+ " login successs" );
}
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn