Share client data between servlets
Posted on 2006-07-19
I have to display a recordset on the same web page as a graph as well as an HTML table. I am using JFreeChart for the graph. The problem I am facing is how do I display both the graph(image) and the HTML table on the same web page using a single servlet. The response type for the image is "image/png" and for the table is "text/html". I am displaying the image by calling a particular servlet from the "src" attribute of an <img> tag which returns the generated image using the responses outputstream. I am not sure if I can use the same servlet to return the HTML table as well..
The main concern is the query shouldnt be run twice , i.e database calls shouldnt happen again as the resultset for both the image and the table is the same..So even if I use different servlets to display the image and the table , I need to share the data structure(a vector in this case which stores the results of the query) in both the servlets.
How do I share data between two different servlets, which would be different per client session. I am thinking of using RequestDispatcher to store the data structure in the Context , however not sure if this is a good approach or not.
Also my application uses opensymphony Action Classes for server side programming.
Experts awaiting your suggestions. Some sample code or links to some sample code would be highly appreciated.