欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java異步方式實(shí)現(xiàn)登錄

 更新時(shí)間:2016年05月22日 08:12:21   作者:舊夢(mèng)vs逆愛(ài)  
這篇文章主要為大家詳細(xì)介紹了java異步方式實(shí)現(xiàn)登錄的相關(guān)資料,感興趣的朋友可以參考一下

本文實(shí)例為大家分享了java異步登錄的具體代碼,供大家參考,具體內(nèi)容如下

1.LoginServletAjax.java  

package 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;
 
public class LoginServletAjax extends HttpServlet {
 
  @Override
  protected void service(HttpServletRequest request,
      HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    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 response) throws ServletException, IOException {
     PrintWriter out = response.getWriter();
   
    // 用戶名
    String username = request.getParameter("username");
    // 密碼
    String password = request.getParameter("password");   
    String 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>chapter3-test2</title>
 
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="this is my page">
    <meta http-equiv="content-type" content="text/html; 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"></link>
 
    <!-- <script type="text/javascript" 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.js"></script>
 
    <script type="text/javascript" src="../UI/locale/easyui-lang-zh_CN.js"></script>
 
    <script type="text/javascript">
  //string number boolean null object undefined function 
  $(function() {
    $("#LoginAdd").dialog({
      title : "用戶登錄",
      collapsible : 'true',
      width : 300,
      height : 200,
      buttons : [ {
        text : '登錄',
        iconCls : 'icon-add',
        handler : function() {
          console.info("用戶登錄!");
          ajaxFrm();//ajax提交表單的函數(shù)
        }
      } ]
    });
 
  });
  function ajaxFrm() {
    //------------------------注釋的是ajax提交方法----------------------------
    var LoginList = $("#LoginList");
     
    $.ajax({
      url : '../LoginServletAjax?tag=test',//相對(duì)路徑訪問(wèn)
      type : 'POST', //提交請(qǐng)求的方式
      data : $('#form1').serialize()+'&names=liuqin&age=26',//將表單參數(shù)序列化,發(fā)送到服務(wù)器的數(shù)據(jù)(提交額外的參數(shù))
      dataType : 'json', //預(yù)期服務(wù)器返回的數(shù)據(jù)類(lèi)型-json object  
      success : function(data) {//請(qǐng)求成功后將調(diào)用此方法var data = {"Msg":"登錄成功","rows":{"username":"admin",...}}
        console.info(data);//調(diào)試代碼
        $.messager.alert("提示", data.Msg);
        LoginList.html("");//清空數(shù)據(jù)
        if (data.rows) {
          var stra = LoginList.html() + "用戶名:" + data.rows.username
              + "--密碼:" + data.rows.password + "<br/>";
          LoginList.html(stra);
        }
      },
      error : function(error) { //請(qǐng)求失敗時(shí)將調(diào)用此方法
        console.info(error);
 
      }
    });
 
     /*var LoginList = $("#LoginList");
     $("#form1").form("submit", {
       url: "../LoginServletAjax?tag=test",
       onSubmit: function (param) { //提交額外的參數(shù)
         param.name="liuqin";
       param.age=27;
         var username = $("#username").val();
         var password = $("#password").val();
         if (username.length == 0 || password.length == 0) {
           $.messager.alert('警告', '請(qǐng)輸入用戶名和密碼');
           return false;
         }
         return true;
       },
       success: function (data) { 
         //var data = eval('(' + data + ')'); 
         var data = $.parseJSON(data);//服務(wù)器端返回json字符串轉(zhuǎn)成json對(duì)象-js object
         console.info(data);
         $.messager.alert("提示", data.Msg);
         LoginList.html("");//清空數(shù)據(jù)
          if (data.rows) {
            var stra = LoginList.html() + "用戶名:" + data.rows.username
                + "--密碼:" + data.rows.password + "<br/>";
            LoginList.html(stra);
          }
       }
     });*/
 
  }
</script>
  </head>
 
  <body>
 
 
    <div id="LoginAdd">
      <form id="form1" method="post">
        <table style="width: 100%;">
          <tr>
            <td>
              用戶名:
            </td>
            <td>
              <input id="username" name="username"
                class="easyui-validatebox textbox">
            </td>
          </tr>
          <tr>
            <td>
              密碼:
            </td>
            <td>
              <input id="password" name="password"
                class="easyui-validatebox textbox" type="password">
            </td>
          </tr>
        </table>
      </form>
    </div>
    <div id="LoginList">
      用戶信息加載中......
    </div>
 
    <video width="320" height="240" controls="controls"
      src="../video/B4934A0C53FC55703BFE3F6843E66166.mp4" type="video/mp4">
      Your browser does not support the video tag.
    </video>
 
 
  </body>
</html>

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家學(xué)習(xí)java程序設(shè)計(jì)有所幫助。

相關(guān)文章

  • java讀取zip/jar包中文件的幾種方式

    java讀取zip/jar包中文件的幾種方式

    這篇文章主要給大家介紹了關(guān)于java讀取zip/jar包中文件的幾種方式,在我們?nèi)粘J褂弥袎嚎s文件是非常常用的,文中通過(guò)示例代碼將java讀取zip/jar包中文件的方法介紹的非常詳細(xì),需要的朋友可以參考下
    2023-07-07
  • 詳解@ConfigurationProperties如何裝載到Spring容器中

    詳解@ConfigurationProperties如何裝載到Spring容器中

    這篇文章主要為大家詳細(xì)介紹了@ConfigurationProperties該如何裝載到Spring容器中,文中的示例代碼講解詳細(xì),需要的小伙伴可以參考一下
    2023-07-07
  • 15個(gè)高級(jí)Java多線程面試題及回答

    15個(gè)高級(jí)Java多線程面試題及回答

    這篇文章主要介紹了15個(gè)高級(jí)Java多線程面試題及回答,翻譯自國(guó)外的一篇文章,這些面試題容易混淆、較難回答,需要的朋友可以參考下吧
    2014-05-05
  • Python爬蟲(chóng)之爬取2020女團(tuán)選秀數(shù)據(jù)

    Python爬蟲(chóng)之爬取2020女團(tuán)選秀數(shù)據(jù)

    本文將對(duì)比《青春有你2》和《創(chuàng)造營(yíng)2020》全體小姐姐,鑒于兩個(gè)節(jié)目的數(shù)據(jù)采集和處理過(guò)程基本相似,在使用Python做數(shù)據(jù)爬蟲(chóng)采集的章節(jié)中將只以《創(chuàng)造營(yíng)2020》為例做詳細(xì)介紹。感興趣的同學(xué)可以照貓畫(huà)虎去實(shí)操一下《青春有你2》的數(shù)據(jù)爬蟲(chóng)采集,需要的朋友可以參考下
    2021-04-04
  • JAVA找不到符號(hào)的三種解決方案

    JAVA找不到符號(hào)的三種解決方案

    這篇文章主要給大家介紹了關(guān)于JAVA找不到符號(hào)的三種解決方案, 找不到符號(hào)錯(cuò)誤主要發(fā)生在我們?cè)噲D引用一個(gè)未在我們正在編譯的程序中聲明的變量時(shí),這意味著編譯器不知道我們所引用的Java變量,需要的朋友可以參考下
    2024-03-03
  • Java中實(shí)現(xiàn) SHA-256加密的兩種方式

    Java中實(shí)現(xiàn) SHA-256加密的兩種方式

    這篇文章主要介紹了Java中實(shí)現(xiàn) SHA-256加密的兩種方式,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧
    2024-01-01
  • springboot項(xiàng)目(jar包)指定配置文件啟動(dòng)圖文教程

    springboot項(xiàng)目(jar包)指定配置文件啟動(dòng)圖文教程

    這篇文章主要給大家介紹了關(guān)于springboot項(xiàng)目(jar包)指定配置文件啟動(dòng)的相關(guān)資料,在多環(huán)境部署過(guò)程中、及線上運(yùn)維中可能會(huì)遇到臨時(shí)指定配置文件的情況,需要的朋友可以參考下
    2023-07-07
  • Mybatis實(shí)現(xiàn)動(dòng)態(tài)SQL編寫(xiě)詳細(xì)代碼示例

    Mybatis實(shí)現(xiàn)動(dòng)態(tài)SQL編寫(xiě)詳細(xì)代碼示例

    這篇文章主要為大家詳細(xì)介紹了Mybatis中動(dòng)態(tài)SQL的編寫(xiě)使用,動(dòng)態(tài)SQL技術(shù)是一種根據(jù)特定條件動(dòng)態(tài)拼裝SQL語(yǔ)句的功能,它存在的意義是為了解決拼接SQL語(yǔ)句字符串時(shí)的痛點(diǎn)問(wèn)題,感興趣想要詳細(xì)了解可以參考下文
    2023-05-05
  • spring boot異步(Async)任務(wù)調(diào)度實(shí)現(xiàn)方法

    spring boot異步(Async)任務(wù)調(diào)度實(shí)現(xiàn)方法

    在沒(méi)有使用spring boot之前,我們的做法是在配置文件中定義一個(gè)任務(wù)池,然后將@Async注解的任務(wù)丟到任務(wù)池中去執(zhí)行,那么在spring boot中,怎么來(lái)實(shí)現(xiàn)異步任務(wù)的調(diào)用了,下面通過(guò)本文給大家講解,需要的朋友參考下
    2018-02-02
  • Java基本數(shù)據(jù)類(lèi)型與對(duì)應(yīng)的包裝類(lèi)(動(dòng)力節(jié)點(diǎn)java學(xué)院整理)

    Java基本數(shù)據(jù)類(lèi)型與對(duì)應(yīng)的包裝類(lèi)(動(dòng)力節(jié)點(diǎn)java學(xué)院整理)

    Java是面向?qū)ο蟮木幊陶Z(yǔ)言,包裝類(lèi)的出現(xiàn)更好的體現(xiàn)這一思想,Java語(yǔ)言提供了八種基本類(lèi)型。六種數(shù)字類(lèi)型(四個(gè)整數(shù)型,兩個(gè)浮點(diǎn)型),一種字符類(lèi)型,還有一種布爾型。 下面通過(guò)本文給大家詳細(xì)介紹,感興趣的朋友一起學(xué)習(xí)吧
    2017-04-04

最新評(píng)論