Results 1 to 9 of 9

Thread: AJAX in JSP

  1. #1
    haiforhussain is offline Member
    Join Date
    Jun 2008
    Posts
    11
    Rep Power
    0

    Default AJAX in JSP

    How to implement AJAX in JSP ...
    can anyone pls give me an example....

  2. #2
    Join Date
    Apr 2008
    Posts
    64
    Rep Power
    0

    Default

    Hi hussain,
    its there in the W3schools dude.. You even have sample code in it.. refer them and post your doubts if any..

  3. #3
    haiforhussain is offline Member
    Join Date
    Jun 2008
    Posts
    11
    Rep Power
    0

    Default

    Quote Originally Posted by freddieMaize View Post
    Hi hussain,
    its there in the W3schools dude.. You even have sample code in it.. refer them and post your doubts if any..
    hi
    I have checked in w3schools.com ... but they given example for asp and php only ... i have searched in google also ... everywhere there is an example for asp and php only ....

  4. #4
    Join Date
    Apr 2008
    Posts
    64
    Rep Power
    0

    Smile

    Hi hussain,

    use the below code and modify accordingly............

    Java Code:
     <script language="JavaScript">
                    
                    function ajax()
                    {   
                        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)
                                {
                                   
                                    var resultTxt=xmlHttp.responseText;
                                 //resultTxt would be your result that you send from the servlet
                                }
                            }
                            var any_parameter= document.formName.any_parameter.value;                      
                            var url="servletName";
                            url=url+"?any_parameter="+any_parameter;//any_parameter- this can be a value of a textbox or something
                            
                            xmlHttp.open("GET",url,true);
                            xmlHttp.send(); 
                        }
                        
                        
                </script>
    try it........
    post if you have any doubts in the above code.........

    cheers..................:)
    freddie

  5. #5
    haiforhussain is offline Member
    Join Date
    Jun 2008
    Posts
    11
    Rep Power
    0

    Default

    hi freddie
    Can u pls explain me how to pass a data from HTML page to JSP ... and how to get the data from jsp using AJAX ....

    cheers
    hussain

  6. #6
    refereence2me is offline Member
    Join Date
    Jun 2008
    Posts
    1
    Rep Power
    0

    Default

    Hi,

    You can pass data from html through hidden parameters...

    From JSP to AJAX the example is already discussed above..

  7. #7
    o0JSP is offline Member
    Join Date
    Jun 2008
    Posts
    5
    Rep Power
    0

    Default

    why not to use DWR? it can help you to use AJAX in an easy way.

  8. #8
    pao
    pao is offline Member
    Join Date
    Jun 2008
    Posts
    43
    Rep Power
    0

    Default

    Quote Originally Posted by haiforhussain View Post
    hi freddie
    Can u pls explain me how to pass a data from HTML page to JSP ... and how to get the data from jsp using AJAX ....

    cheers
    hussain
    I think Freddie gave you a pretty decent example of how to implement AJAX.... You see you need to replace the string value "servletname" with the servlet you wish to handle you request. Pass params to the servlet with the url first (its easier) capture them on the servlet with request.getParameter calls. When you have your values, do your workings and write the response back.... In that way you will have successfully passed your values back to the jsp\servlet without submitting the form and posting back to your own page.

  9. #9
    Join Date
    Apr 2008
    Posts
    64
    Rep Power
    0

    Default

    Hi hussain,
    Are you still having the doubt?

    And are you sure about your question. I mean
    Quote Originally Posted by haiforhussain View Post
    Can u pls explain me how to pass a data from HTML page to JSP
    If that is the case then you can use hidden fields (like one of our friend mentioned).

    Regards,
    Freddie

Similar Threads

  1. alternative for ajax
    By site4u in forum New To Java
    Replies: 6
    Last Post: 04-28-2011, 01:15 PM
  2. Jsp with Ajax
    By sundarjothi in forum JavaServer Pages (JSP) and JSTL
    Replies: 16
    Last Post: 09-25-2008, 10:29 AM
  3. Example for Ajax-JSP
    By smrithi in forum JavaServer Pages (JSP) and JSTL
    Replies: 8
    Last Post: 06-02-2008, 02:00 PM
  4. JAVA, Ajax, Flash
    By Digital Dispatching in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 02-06-2008, 07:49 AM
  5. Ajax question
    By Peter in forum New To Java
    Replies: 1
    Last Post: 07-09-2007, 12: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
  •