Response XML Parsing and building an HTML table using AJAX
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Anonymous
Posted On:   Wednesday, November 14, 2007 05:01 PM

Hi, I am newbie on AJAX. I have been trying to build a sample application using AJAX. Even though the concept is pretty straightforward, the implementation is not. To begin with, I first made a simple non-AJAX application which has a JSP calling a simple Servlet. The Servlet has some JDBC code which calls a table using "select *" and gets the ResultSet in an ArrayList of Value Objects (Java beans which have same fields as the columns/attributes in the table). Once the ArrayList is built, the same is put in HttpSession and the response is sent back to the JSP where the ArrayList is obtained from session and shown by applying some Scriptlets. How do you suppose this will be easily implemented using AJAX   More>>

Hi,


I am newbie on AJAX. I have been trying to build a sample application using AJAX. Even though the concept is pretty straightforward, the implementation is not.
To begin with, I first made a simple non-AJAX application which has a JSP calling a simple Servlet. The Servlet has some JDBC code which calls a table using "select *" and gets the ResultSet in an ArrayList of Value Objects (Java beans which have same fields as the columns/attributes in the table). Once the ArrayList is built, the same is put in HttpSession and the response is sent back to the JSP where the ArrayList is obtained from session and shown by applying some Scriptlets.


How do you suppose this will be easily implemented using AJAX. Let me define the flow which I think will happen. You can correct me if I go wrong anywhere -

      1) JSP calls the URL through the javascript function.

      2) The servlet is not a normal servlet but one that sends an XML back in the response by using response.getWriter().write(" some message "); function and also by putting esponse.setContentType("text/xml");

      3) The JSP receives the response XML and parses the xml in a special javascript function. This function at the same time builds an InnerHTML or replaces the HTML DOM structure with the intended new structure.



This seems easier said than done. The HTML which I need to create is an entire table having

, tags and whic has nested scriptlets having for loops and if control statements to loop over the Arraylist (obtained from HTTPSession) and to get Java Objects which are typecasted into specific Value Objects.


The last part of creating an HTML Table inside the JSP by obtaining the reponse XML from the servlet seems so much difficult! Can someone suggest how is it done in large applications using AJAX which also have a need of displaying data in tabular format fetched from tables.

If you have a link which shows such an example, you are welcome to post it.




Eagerly waiting for some response,

Vaibhav Beohar
,
   <<Less

Re: Response XML Parsing and building an HTML table using AJAX

Posted By:   Anonymous  
Posted On:   Monday, November 19, 2007 12:37 PM

Hi,

The entire table can be created dynamically using javascript. The table you want to create should be given an id so that getElementById works on the table.









Hope this throws some light on your problem.

Cheers,

Naren
About | Sitemap | Contact