Tuesday, November 1st, 2005

jsquery: Ajax Javascript result set, http client and server code generator

Category: Java, JavaScript, Library

jsquery is a bridge project, written by David Bennett, that allows you to write JavaScript code on your HTML front end, that will marshall over to a Java server backend to get access to data.

This can be done in an asynchronous manner.


jsquery is divided into three parts:

  1. Javascript http client

    {WebRoot}/js/jsquery_httpclient.js – A javascript http client that calls a server side query and evaluates the results into a jsquery_resultset

  2. Java server side generator in src/com/bensoft/jsquery

    JSGenerator.java – Generates a javascript representation of a 2D data matrix into a jsquery_resultset instance

    ResultSet2JS.java – Converts a Java JDBC ResultSet into javascript using JSGenerator

    Types.java – Defines the simplified types for jsquery_resultset.js which include Number, String, Date, and Boolean.

  3. Javascript ResultSet

    {WebRoot}/js/jsquery_resultset.js – A javascript implementation of the JDBC ResultSet that reads from aquery result embedded into a series of javascript arrays that are generated by the server.

Test of jsquery HTTPClient

// Make a request for data
var hc = new jsqueryHTTPClient();
hc.setComplete(new Function("show_results(this.getResult())"));

// Show the results
function show_results(scr){
  // evalulate the result from the server

  // generate an HTML table into String
  var html=new String("");
  // Example JDBC calls
  var name=rs.findColumn("name");
  var phone=rs.findColumn("phone");
  while (rs.next()) {
  // Finish the table
"); // Find the layer to place the results in if (document.getElementById) { x=document.getElementById("results"); x.innerHTML=''; x.innerHTML=html; } else { // old style document.open(); document.write(html); document.close(); } }


Posted by Dion Almaer at 9:09 am

3.6 rating from 9 votes


Comments feed

Is this really a good idea? I blogged about it here as it got too long for a comment:


Comment by Rob — November 1, 2005

Agree with Rob…

This is an unintuitive solution, to embed recieved data one needs to loop through the data with JS which results in unnecessary javascript code…


Comment by Hakan Bilgin — November 1, 2005

Always good to hear alternative opinions chime in.

For the record:

jsquery does not circumvent a good MVC model in anyway. The ResultSet can be completely managed by the controller which is what the example code demonstrates. The ResultSet is merely a well defined 2D data delivery pattern that is universally understood. jsquery leverages existing API’s which is a good thing and dramatically shortens the learning curve.

In production we use jsquery with an OR Mapper for the model and a full controller using POJO (I’m not big on overblown architectures that add bloated unnecessary layers of code to an application).

The other thing to note:


Much faster than a great deal of the piggy XML based solutions that are out there.

jsquery allows you to add AJAX functionality to your web applications without learning a new API and adopting gigantic new proprietary paradigms.

As for the ‘unnecessary javascript code’ please refer to the examples. The client side code is very tight and small, much smaller than other AJAX implementations.

Comment by David Bennett — November 2, 2005

The jsquery architecture is not really any different then most MVC frameworks out there.

Current Frameworks (Struts, WebWork, etc..)

1. Execute query on db
2. Write results into Java Object
3. JSP renders results from the Java Object, or loops through a list of objects depending on what type of page it is.


1. Execute query on db.
2. Write results into JS Array.
3. View can access the array (through JDBC like methods) and displays information to the page.

As Dave said, the JS is being directly returned to the view from the server request. It is NOT getting back xml that has to be traversed to build the array. This makes jsquery very fast.

The fact that data can be retrieved without having to do a page refresh will greatly increase the speed of an app. Not to mention stop most of the need to have parameters being passed everywhere to maintain the current page state in-between refreshes.

IMHO, more and more people are going to be gravitating towards httprequest/ AJAX. Especially with the success Google is having with it, and MS is now making a push towards it as well.

My 2 cents….


Comment by Paul Zepernick — November 5, 2005

Yeah, AJAX…

Comment by fgsdgsg — August 19, 2007

Leave a comment

You must be logged in to post a comment.