skip to main content
Charts > Programmer's documentation > Building Web Applications > Developing JViews Charts JavaScript Web applications > The IlvChartServlet class
 
The IlvChartServlet class
The JViews Charts library provides a predefined lightweight servlet abstract class named IlvChartServlet. This class is a subclass of the HttpServlet class from the Java servlet API that automatically delegates the requests handling to an instance of IlvChartServletSupport.
*Creating an IlvChartServletSupport
*Describes the creation of an IlvChartServletSupport subclass.
*Handling sessions
*Describes how to handle HTTP sessions using the IlvChartServlet class.
Creating an IlvChartServletSupport
This instance is created by the IlvChartServlet when the first request is received. Since the IlvChartServletSupport class is abstract and should be subclassed, the instance is created by the abstract createServletSupport factory method, which has to be overridden to return an instance of your own IlvChartServletSupport subclass.
Handling sessions
The IlvChartServlet class supports the HTTP session concept by means of the prepareSession method. This method is called at every request to allow the user to prepare and configure a session for his servlet.
Assume a servlet only uses one IlvChart instance shared between all the clients. If this architecture works well in a read-only context, it does not work anymore if the data model can be modified by the clients. Indeed, any modification of the chart data model made by a client would be seen by all the clients. A solution is to create a session for every request. You can then create one IlvChart connected to a specific data model and store it as a parameter of the session. In this way, a chart is created for each session opened by a client instead of being created for all the clients.
Another aspect to consider when you work with sessions is memory leak. When you bind a chart as an attribute of an HttpSession, proper cleanup of the chart must occur when the session is invalidated or expires. This allows the chart to be garbage collected or restored to a pool of available charts, depending on your choice of strategies. Instead of binding the chart directly to the session, use an instance of the IlvChartSessionAttribute as a proxy.
The following code extract shows how to use it:
IlvChart chart = null;
HttpSession session = request.getSession();
if (session.isNew()) {
   chart = ... create new chart or fetch from pool ...
   IlvChartSessionAttribute proxy = new IlvChartSessionAttribute(chart);
   session.setAttribute(CHART_KEY, proxy);
} else {
   IlvChartSessionAttribute proxy =
     (IlvChartSessionAttribute)session.getAttribute(CHART_KEY);
   if (proxy != null)
     chart = proxy.getChart();
}
if (chart == null)
   throw new ServletException("session problem");

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.