AD

A simple example AJAX asynchronous communication

textarea  Asynchronous submission loses focus  

index.jsp  The key code is as follows  :

  First step  :  Other controls can also be written page  ,  Not limited to  textarea

<s:form action="" method="post">
         <div >
           <p >   Mood today  :</p>
       <p >
        <textarea name="signature"  ><s:property value="user.signature"/>  //siganature   Is an attribute of user object  
        </textarea>
       </p>
      </div>
  </s:form>

  The second step :  In these pages  <head></head>  Add the following between the  js
<script language="javascript">

//  Define a variable to hold the XMLHttpRequest object     
   var xmlHttp;   
   var deleteStatus ;//  Status page deleted storage form  
   //  Change function is used to create an XMLHttpRequest object     
   function createXMLHttpRequest(){   
       if(window.ActiveXObject){   
           xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");   
       }else if(window.XMLHttpRequest){   
           xmlHttp = new XMLHttpRequest();   
       }   
   }   

   //  This is a way to start the AJAX asynchronous communication     
   function ajax_submit(){   
      
       //  Create an XMLHttpRequest object     
       createXMLHttpRequest();   

       //  Bound to a function of the state     
       xmlHttp.onreadystatechange=processAjax;   
       //  Specified by POST method to  URL  Established call to the server     
       var url="<%=basePath%>/workPlanAction!deleteWorkPlanDetail.action?dto.workplanDetailId="+detailid;   
       xmlHttp.open("POST",url,true);  

       //  Send request     
       xmlHttp.send(null);   
   }   
   //  This is a function to handle the state change     
   function processAjax(){   
       // Define a variable to hold the results returned from the server response     
       var responseContext="";   
       if(xmlHttp.readyState==4){   
           if(xmlHttp.status==200){   
               responseContext = xmlHttp.responseText;    
             // document.getElementById("ta").value=responseContext;   
           }   
       }   
   }  

</script>



  The third step  :  Class action prepared     Key code  

//  Importing packages to be omitted  

public class UpdateSignatureAction extends ActionSupport implements ServletRequestAware{

public String execute(){

String responseText="";   
        //  Read request parameters     
        HttpServletRequest request = ServletActionContext.getRequest();   
        responseText=request.getParameter("signature"); 
        responseText=new String(responseText.getBytes("ISO-8859-1"),"GBK"); //  Remove this line, there will be garbled  
  HttpServletResponse response = ServletActionContext.getResponse();   
  response.setContentType("text/plain");//  Set the output to a text stream    
        response.setCharacterEncoding("UTF-8");   
        PrintWriter out = response.getWriter();   

        //  Directly to the content of the output response     
        out.println(responseText);   
        out.flush();   
        out.close(); 

  Other signature persisted to the database will be operating as spent  

return null;

}

}
标签: lt, jsp, script language, js, ajax, language javascript, signature, xmlhttprequest, new activexobject, readystate, microsoft, div, textarea name, getelementbyid, asynchronous communication, basepath
分类: Java
时间: 2011-04-27

相关文章

  1. Jquery Ajax asynchronous communication problem to solve

    $.ajax({ type:"post", url:"inputCodeSearch.action", data:"sign=addEnter&code=&quo ...
  2. Driver and application level asynchronous communication

    Author: sislcb Time: 2008-01-28,11:13:28 Links: http://bbs.pediy.com/showthread.php?t=59015 Here to explain th ...
  3. Request on the server side to determine a request from the Ajax (asynchronous) or a traditional request (synchronous)

    Request on the server side to determine a request from the Ajax (asynchronous) or a traditional request (synch ...
  4. Transfer system. Synchronous and asynchronous communication system model

    Transfer systems, synchronous and asynchronous communication system model
  5. actionscript ajax asynchronous server requests

    actionscript 3.0 ajax asynchronous request java servlet server specific code written in a new layer first fram ...
  6. ajax asynchronous request encoding problem

    ajax asynchronous request allows us to easily jump page in no case to show the data coming back after treatmen ...
  7. c # asynchronous communication of two forms each switch port to listen on both the form of two seasons there can not be switched 4 receive data

    The recent project needs, need to use socket, demand is such, there are many sets of data collection server, a ...
  8. php file upload with Ajax asynchronous code examples

    php file upload with Ajax asynchronous code examples 1: Get the file object 2: Read binary data 2 3: Simulatio ...
  9. With the background using Ajax Servlet asynchronous communication

    function createXmlHttpRequest(){ var oXmlHttp; if(window.XMLHttpRequest){ // Non-IE browser oXmlHttp = new XML ...
  10. java simple implementation of remote communication technologies and

    Transfer from this article: http://staratsky.javaeye.com/blog/345593 In a distributed service framework, one o ...
  11. Ajax Asynchronous Request Server (jquery) server returns data in xml format

    New jslib the WebRoot directory folder: the lib into the jquery library, verifyjqueryxml.js (script file) ajax ...
  12. Ajax Asynchronous mode synchronization

    Although Ajax can be set to synchronous or asynchronous mode, but in some cases (such as cross-domain ajax cal ...
  13. On the meaning of ajax asynchronous

    ajax send asynchronous requests to the server, the server receives and processes the request, in this period, ...
  14. jquery ajax Ajax original examples of such a simple _jquery ajax

    Always wanted to study under Ajax, no time, sweat, this excuse is too far-fetched. Under the point of tutorial ...
  15. The Ajax asynchronous file upload cakephp <excerpt>

    why? The same need to fill in the information and upload files, save a step by step to avoid loss of informati ...
  16. jquery's ajax () asynchronous transfer List.Map

    Since the project needs to get back in the List object ajax inside the value, since no previous contact with j ...
  17. Ajax asynchronous call servlet - Note the path

    -------------- Jsp - <% @ Page language = "java" import = "java.util .*" pageEncoding = ...
  18. Asynchronous Server Socket Example Asynchronous communication server

    using System; using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; // State ...
  19. Simple boost to achieve communication

    client side: #include "stdafx.h" #include <iostream> #include <boost/asio.hpp> int main( ...