I'm a beginner in Ajax with JSP and Servlets
3 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ariel_Romero
Posted On:   Friday, June 2, 2006 03:07 PM

Hi everybody:

I'm a beginner in Ajax world. But the more I looking for information about Ajax with Java the less easy is for me to develop my application.

I need to do a simple example: a jsp page that query the database and show the list of results without refresh the whole page.

Can you help me, please ???
I need help.

Re: I'm a beginner in Ajax with JSP and Servlets

Posted By:   Anonymous  
Posted On:   Tuesday, June 6, 2006 01:07 AM

I need one sample codeing embedded with jsp using Ajax.
please Sir....

Re: I'm a beginner in Ajax with JSP and Servlets

Posted By:   Robert_Lybarger  
Posted On:   Saturday, June 3, 2006 10:25 AM

Try these examples.

You will have to download them to your machine... they won't work where they are posted, that's just somewhere to post the files. Note I only tested these on FF on a Mac, but FF on windows should be equivalent. Don't know how well the IE bits will behave.

Re: I'm a beginner in Ajax with JSP and Servlets

Posted By:   Robert_Lybarger  
Posted On:   Saturday, June 3, 2006 08:23 AM

Let me suggest you break the problem into a few parts:
  • A JSP page that returns text (or maybe XML, but that's a bit fancier and has a couple more hoops for learning-sake)... this text is a snippet of HTML code that will replace something on the page. You may can explicitly set the return type to "text/plain" here. If you go XML, you'll need "text/xml". Test this works by pointing directly at the JSP page and verifying you get plain text (or XML) but not a standard web page.

  • A simplified HTML page with some javascript. For this part, just have a button with an onClick event. When pressed, it calls a function that just adds some HTML code under some existing object. Play around with:
    document.getElementById("some_div_id_here").innerHTML = "

    This is a test.

    ";

  • Verify you can get the HTTPRequest to work ... in the function that handles the [successful] response, just have it pop up a window.alert("it works"); or something similar.

  • Put these pieces together w/o worrying about the database yet; just return a fixed value. The response handling function sets the innerHTML of some element on your page to be the value of the responseText from the ajax resopnse.

  • Convert the JSP page to get data it needs from a database, but carefully return info to the client in the same general format you already have working.


Now you might start asking for help in pieces instead of just all at once.
About | Sitemap | Contact