本文实例为大家分享了java异步登录的具体代码、供大家参考、具体内容如下
1.Loginervletajax.java
パッケージcom.scce.servlet; java.io.ioexception; import java.io.printwriter; javax.servlet.servletexception; import javax.servlet.http.httpservlet; Import javax.servlet.http.httpservletrequest; Import javax.servlet.http.httpservletresponse; net.sf.json.jsonobjectをインポートします。 com.scce.dao.adminuserdaoをインポート;インポートcom.scce.pojo.adminuser;パブリッククラスのloginservletajaxは、httpservletを拡張します{@override保護されたvoidサービス(httpservletrequest request、httpservletresponse応答)スローServletexception、ioexception {// todo auto-generated method request.setcharacterencoding( "utf-8"); Response.setContentType( "text/html; charset = utf-8"); string method = request.getMethod(); if(method.equals( "post")){dologinajax(request、response); } else if(method.equals( "get")){}} public void dologinajax(httpservletrequest request、httpservletResponse応答)servletexception、ioexception {printwriter out = response.getwriter(); //用户名文字列username = request.getParameter( "username"); //密码文字列パスワード= request.getParameter( "パスワード");文字列msg = ""; adminuserdao adminuserdao = new adminuserdao(); adminuser adminuser = adminuserdao.queryuser(username、password); if(adminuser!= null){msg = "登录成功!"; string jsonobj = jsonobject.fromobject(adminuser).toString(); out.print( "{/" msg/":/" "+msg+"/"、/" rows/":"+jsonobj+"}"); System.out.println( "{/" msg/":/" "+msg+"/"、/" rows/":"+jsonobj+"}"); } else {msg = "用户名或者密码不正确!"; out.print( "{/" msg/":/" "+msg+"/"}"); } out.flush(); out.close(); }} 2.test2.html
<!Doctype html> <html> <head> <title> Chapter3test2 </title> <meta http-equiv = "keywords" content = "keyword2、keyword3"> <meta http-equiv = "description" content = " charset = utf-8 "> <link rel =" styleSheet "href =" ../ ui/themes/icon.css "type =" text/css "> </link> <link rel =" styleSheet "href =" ../ ui/themes/default/easyui.css "type =" text/css src = "../ js/jquery-1.8.2.min.js"> </scrip> - > <script type = "text/javascript" src = "../ ui/jquery.min.js"> </script> <スクリプトタイプ= "text/javascript" src = "../ ui/jquery.ey.min.js type = "text/javascript" src = "../ ui/locale/easyui-lang-zh_cn.js"> </script> <script = "text/javascript"> // string boolean null object未定義$(function(){$( "#loginadd")。ボタン:[{text: '登录'、iconcls: 'icon-add'、handler:function(){console.info( "用户登录!"); ajaxfrm(); // ajax}}]}); }); function ajaxfrm(){// ---------------------注释的是ajax提交方法--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- $ .ajax({url: '../loginervletajax?tag = test',//相对路径访问タイプ:' post '、//提交请求的方式データ:$('#form1 ')。 data = {"msg": "登录成功"、 "rows":{"username": "admin"、...}} console.info(data); // + data.username + "- + data.rows.password +"; /*var loginlist = $( "#loginlist"); $( "#form1")。form( "submit"、{url: "../loginervletajax?tag=test"、onsubmit:function(param){// || length == 0){'警告')、false:false( '(' + data + '); $ .MESSAGER.ALERT( "提示"、data.mtml( ""); }} id = "password" name = "password" type = "password"> </td> </tr> </table> </form> </div> <div id = "loginlist">用户信息加载中...... </div> <ビデオコントロール= "controls" src = "../ video/b4934a0c53fc555703bfe3f6843e63e6661666666666666666666666666 type = "video/mp4">ブラウザはビデオタグをサポートしていません。 </video> </body> </html>以上就是本文的全部内容、希望对大家学习java程序设计有所帮助。