本文实例为大家分享了 Java a, 供大家参考, 具体内容如下
1. loginservletajax.java
패키지 com.scce.servlet; import java.io.ioexception; import java.io.printwriter; import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse; import net.sf.json.jsonobject; import com.scce.dao.adminuserdao; import com.scce.pojo.adminuser; 공개 클래스 loginservletajax는 httpservlet {@override protected void service (httpservletrequest request, httpservletreponse response)를 servletexception, ioexception {// a auto-auto-generated method stub request.setcharacterencoding ( "utf-8")에 확장합니다. Response.setContentType ( "Text/Html; charset = utf-8"); 문자열 메소드 = request.getMethod (); if (method.equals ( "post")) {dologinajax (요청, 응답); } else if (method.equals ( "get")) {}} public void dologinajax (httpservletrequest request, httpservletreponse responsk) servletexception, ioexception {printwriter out = respint.getWriter (); // 用户名 string username = request.getParameter ( "username"); // string password = request.getParameter ( "password"); 문자열 msg = ""; inminuserdao inminuserdao = new AdminUserDao (); 관리자 관리자 = 관리자 QueryUser (사용자 이름, 비밀번호); if (관리자! = null) {msg = "登录成功!"; 문자열 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> chapt3-test2 </title> <meta http-equiv = "keywords"content = "keyword1, keyword2, keyword3"> <meta http-equiv = "descript"is page <meta http-equiv = "컨텐츠/http-equiv ="컨텐츠/http-equiv =; charset = utf-8 "> <link rel ="스타일 시트 "href ="../ ui/tremes/icon.css "type ="text/css "> </link rel ="stylesheet "href ="../ ui/espault/easyui.css "type/css"> </link> src = "../ js/jquery-1.8.2.min.js"> </script>-> <script type = "text/javaScript"src = "../ ui/jquery.min.js"> </script> <script type = "text/javascript"src = "../ ui/jquery.easyui.min.j> 유형 = "text/javaScript"src = "../ ui/locale/easyui-lang-zh_cn.js"> </script> <script type = "text/javaScript"> // 문자열 번호 부울 null 객체 undefined function $ (function () {$ ( "#loginadd"). 200, 버튼 : [{text : '登录', iconcls : 'icon-add', handler : function () {console.info ( "用户登录!"); ajaxfrm (); // ajax 提交表单的函数}}}); }); 함수 ajaxfrm () {// ------------------------------------------------------------------- var loginList = $ ( "#loginList"); $ .ajax ({url : '../loginservletajax?tag=test' ,// 相对路径访问 type :'post ', // 提交请求的方式 data : $ ('#form1 '). serialize ()+'& names = liuqin & age = 26 ', // 将表单参数序列化 将表单参数序列化, 发送到服务器的数据 (提交额外的参数) datatype :'json ', // json 객체 (데이터) = { "msg": "登录成功", "행": { "username": "admin", ...}} console.info (data); // 调试代码 $ .messager.alert ( "提示", data.msg. data.rows.username + "-" + data.rows.password + "<br/>"; /*var loginList = $ ( "#loginList"); $ ( "#form1"). form ( "제출", {url : "../loginservletajax?tag=test", onsubmit : onsubmit : function (param) {// 提交额外的参数 param.name = "liuqin"; param.age = 27; var username = $ ( "#username"); val (password). || $ .messager.alert ( "提示", data.msg); html ( "") {data.rows) {var stra = loginlist.html () 用户名 : " + data.username +"-" + data.rows."; });*/} </script> </head> <body> <div id = "loginadd"> <form id = "form1"method = "post"> <table> <tr> <td> 用户名 : </td> <td> <input id = "username"name = "username"> id = "password"name = "password"유형 = "password"> </td> </td> </td> </table> </div> <div id = "loginList"> 用户信息加载中 ...... </div> <video controls = "controls"src = "../ video/b4934a0c53fc5703bfe3f6843e6616.mp4" type = "video/mp4"> 브라우저는 비디오 태그를 지원하지 않습니다. </video> </body> </html>以上就是本文的全部内容 以上就是本文的全部内容, 希望对大家学习 java 程序设计有所帮助。