I have a JSP page that queries a MySQL database, I want to send the Resultset object to an HTML page as a response object? I need the resultset object to populate a table and a chart.
-
How do I cast the resultSet object into a javascript object?
-
How do I send a resultSet object from JSP to HTML? (I mean the syntax)
I am using get xmlHTTPrequest to call the JSP page
Don’t use JSP. Use a Servlet which queries the DB, obtains a
Listwith results and converts it to a JSON string which JS can seamlessly use.First create a javabean class which represents a single row of the DB table. E.g.
Product.The create a DAO class which fires the query and maps the
ResultSetto aList<Product>.Then create a Servlet class which uses the DAO class to obtain the products and converts it to a JSON string with a little help of Google Gson.
Map this servlet in
web.xmlon anurl-patternof/productsand call it in JavaScript as follows (I am using jQuery since it eliminates crossbrowsersensitive boilerplate so that you end up with 10 times less JavaScript code).