Results 1 to 9 of 9
  1. #1
    smrithi is offline Member
    Join Date
    Jan 2008
    Posts
    3
    Rep Power
    0

    Default Example for Ajax-JSP

    Anyone knows as to how to use Ajax with JSP. I have found out that we can use JSP tags for using Ajax with JSP. I got an example for using Ajax with Jsp at Learn AJAX but here, they have not used JSP tags. The example works. But I want to know how to use JSP tags.

  2. #2
    anki1234 is offline Member
    Join Date
    Dec 2007
    Posts
    28
    Rep Power
    0

    Default

    which jsp tag u want to use

  3. #3
    smrithi is offline Member
    Join Date
    Jan 2008
    Posts
    3
    Rep Power
    0

    Default

    I am a newbie to JSP tags. Want to actually know how to use them and where to start off to use them to get Ajax thing in my jsp pages

  4. #4
    anki1234 is offline Member
    Join Date
    Dec 2007
    Posts
    28
    Rep Power
    0

    Default

    Hi,
    this is a small application in ajax which i made few months back.Hope it will help u
    caller.jsp :
    <&#37;@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    ">

    <html>
    <head>
    <script src="ajax.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page using AJAX</title>
    </head>
    <body>

    <a onclick="sendRequest('GET','index.jsp')" href="#">Server Date Time:</a>
    <div id="ajax_res">Server Date Time will replace this text.</div>
    </body>
    </html>

    index.jsp
    <html>
    <body>
    <%=new java.util.Date()%>
    </body>
    </html>

    ajax.js
    function createRequestObject(){
    var req;
    if(window.XMLHttpRequest){
    //For Firefox, Safari, Opera
    req = new XMLHttpRequest();
    }
    else if(window.ActiveXObject){
    //For IE 5+
    req = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else{
    //Error for an old browser
    alert('Your browser is not IE 5 or higher, or Firefox or Safari or Opera');
    }

    return req;
    }

    //Make the XMLHttpRequest Object
    var http = createRequestObject();

    function sendRequest(method, url){
    if(method == 'get' || method == 'GET'){
    http.open(method,url);
    http.onreadystatechange = handleResponse;
    http.send(null);
    }
    }

    function handleResponse(){
    if(http.readyState == 4 && http.status == 200){
    var response = http.responseText;
    if(response){
    document.getElementById("ajax_res").innerHTML = response;
    }
    }
    }
    run this application may be u get some clue

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  6. #6
    smrithi is offline Member
    Join Date
    Jan 2008
    Posts
    3
    Rep Power
    0

    Default

    I wanted to use JSP tags to build Ajax web site. But in the example you gave, you dint specify about any tag usage.. There are jsp tags which are used when we use ajax in jsp.
    Thanks for ur example

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  8. #8
    Join Date
    Jun 2008
    Posts
    15
    Rep Power
    0

    Default

    smrithi
    Member OK FRIEND DO NOT WORRY.YOU REFER HEAD FIRST JAVA BOOK FOR JSP TAGS AND JSTL.BYEEEEEE.

  9. #9
    Join Date
    Jun 2008
    Posts
    15
    Rep Power
    0

    Default

    If You Refer Orielly Publications Books You Get The Perfection On Jsp Tags,jstl And Custom Tags Also.i Am Pradeep From Mysore .byeeeeeeee.

Similar Threads

  1. alternative for ajax
    By site4u in forum New To Java
    Replies: 6
    Last Post: 04-28-2011, 02:15 PM
  2. JAVA, Ajax, Flash
    By Digital Dispatching in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 02-06-2008, 08:49 AM
  3. how to contact servlet from clientside through ajax
    By santhoskumara in forum Advanced Java
    Replies: 2
    Last Post: 08-10-2007, 07:56 AM
  4. Ajax question
    By Peter in forum New To Java
    Replies: 1
    Last Post: 07-09-2007, 01:43 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •