• Home
  • New Entries
  • Popular Entries
  • Submit a Story
  • About

The Most Basic Ajax With Java ...

Ajax is revolusioner method in building web application, it’s used javascript XMLHttpRequest object to communicate with server without have to reloading the page.

Ajax is revolusioner method in building web application, it’s used javascript XMLHttpRequest object to communicate with server without have to reloading the page.

I am new to Ajax, this is my “hello world” application to show how using Ajax with Java.

(ajaxHello.jsp)
view plaincopy to clipboardprint

   1. <html> 
   2.  
   3. <head> 
   4.  
   5.     <title>Hello Ajax</title> 
   6.  
   7. </head> 
   8.  
   9. <body> 
  10.  
  11.     <script type="text/javascript"> 
  12.  
  13.         function ajaxFunction() 
  14.  
  15.         { 
  16.  
  17.         var xmlHttp; 
  18.  
  19.                 try 
  20.           { 
  21.           // Firefox, Opera 8.0+, Safari 
  22.           xmlHttp=new XMLHttpRequest(); 
  23.           } 
  24.         catch (e) 
  25.           { 
  26.           // Internet Explorer 
  27.           try 
  28.             { 
  29.             xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); 
  30.             } 
  31.           catch (e) 
  32.             { 
  33.             try 
  34.               { 
  35.               xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); 
  36.               } 
  37.             catch (e) 
  38.               { 
  39.               alert("Your browser does not support AJAX!"); 
  40.               return false; 
  41.               } 
  42.             } 
  43.           } 
  44.                   xmlHttp.onreadystatechange=function() 
  45.             { 
  46.                 if(xmlHttp.readyState==4) 
  47.                 { 
  48.                     document.getElementById("timeInfo").innerHTML=xmlHttp.responseText; 
  49.                 } 
  50.             } 
  51.                         xmlHttp.open("GET","time.jsp",true); 
  52.             xmlHttp.send(null); 
  53.         } 
  54.     </script> 
  55. <form name="aForm"> 
  56. Name: <input type="text" name="username" onkeyup="ajaxFunction();" /> 
  57. Hi, you are typing the text at 
  58. <span id="timeInfo" STYLE="font-family: sans-serif; color: red; font-size: 12pt"></span> 
  59. </form> 
  60. </body> 
  61. </html> 

<html>

<head>

    <title>Hello Ajax</title>

</head>

<body>

    <script type="text/javascript">

        function ajaxFunction()

        {

        var xmlHttp;

                try
          {
          // Firefox, Opera 8.0+, Safari
          xmlHttp=new XMLHttpRequest();
          }
        catch (e)
          {
          // Internet Explorer
          try
            {
            xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
            }
          catch (e)
            {
            try
              {
              xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
              }
            catch (e)
              {
              alert("Your browser does not support AJAX!");
              return false;
              }
            }
          }
                    xmlHttp.onreadystatechange=function()
            {
                if(xmlHttp.readyState==4)
                  {
                      document.getElementById("timeInfo").innerHTML=xmlHttp.responseText;
                  }
            }
                          xmlHttp.open("GET","time.jsp",true);
              xmlHttp.send(null);
        }
    </script>
<form name="aForm">
Name: <input type="text" name="username" onkeyup="ajaxFunction();" />
Hi, you are typing the text at
<span id="timeInfo" STYLE="font-family: sans-serif; color: red; font-size: 12pt"></span>
</form>
</body>
</html>

(time.jsp)

view plaincopy to clipboardprint

   1. <strong><%= new java.text.SimpleDateFormat("dd MMM yyyy, hh:mm:ss").format( new java.util.Date() ) %> 
   2. </strong> 

source: gardiary.wordpress

 View Full Story.
Posted at 12:44:43 pm | Permalink | Posted in Java  

Related Stuff

  • MooV: Using cutting edge Video phones and Software Video Phones - coupling all that with VoIP and empowering the disabled.

  • Moo Telecom: VoIP communications made easy - Ring anyway with the fun and ease of using a normal phone

  • TagR:Mobile Social Network with Real Time Locations Based services, and Ambience Intelligence, VoiP, IM, Skype, Googletalk, Mapping, Flickr, Events, Calendaring, Scheduling, SecondLife Support

  • ClearSMS : ClearSMS is a Web-based application that lets you send bulk SMS messages to your customers, contacts, or just about anyone.

  • Jajah:jah is a VoIP (Voice over IP) provider, founded by Austrians Roman Scharf and Daniel Mattes in 2005[1]. The Jajah headquarters are located in Mountain View, CA, USA, and Luxembourg. Jajah maintains a development centre in Israel.

  • Skype: It’s free to download and free to call other people on Skype. Skype the number one voice over ip software

  • PrivatePhone: a free local phone number with voicemail and messages you can check online or from any phone.

Be the first ... |Add your comment.

Your Comment ...

  Name (required)

  Email (required, hidden)

  Website


Top Stuff

e-messenger

MessengerFX

eBuddy

ILoveIM

AIM Express

Top 20 Ruby CMS


Our Partners

Facebook Applications

Ajax Projects

Web 2.0 Sites

Webloglines

Human Development Handbook

Software Development Company

Ajaxlines

Stock Exchange Chat


About Ajaxlines

Ajaxlines is a project focused on providing its audience with a database of most of Ajax related articles, resources, tutorials and services from around the world.

Its purpose is to showcase the power of Ajax and to act as a portal to the Ajax development community.


Search


Topics

  • .Net (114)
  • Articles (87)
  • Bookmarking (35)
  • Calendar (19)
  • Chat (40)
  • ColdFusion (3)
  • CSS (45)
  • Email (23)
  • Facebook (31)
  • Flash (16)
  • Games (6)
  • Google (29)
  • Html (14)
  • Image (11)
  • International Calls & VOIP (7)
  • Java (36)
  • Javascript (179)
  • JSON (21)
  • Perl (2)
  • PHP (91)
  • Presentation (19)
  • Python (3)
  • Resources (2)
  • RSS (1)
  • Ruby (11)
  • Storage (4)
  • Toolkits (90)
  • Tutorials (201)
  • UI (12)
  • Utilities (171)
  • Web2.0 (15)
  • XmlHttpRequest (22)
  • YUI (4)

© 2006 www.ajaxlines.com. All Rights Reserved. Powered by IRange