Implementing the Servlet
Incorporating the graph servlet into your web page involves the following steps,
Step 1 - Load the Servlet Class files into your Servlet Engine
In order to use the Line Graph servlet you will need to have a servlet engine already setup and configured on your web server. There are a wide variety of servlet engines available and as such specific details for each engine are beyond the scope of this documentation. As such we will limit this discussion to the following two engines,
Tomcat - for full details see http://jakarta.apache.org/tomcat/
Servletrunner ( runs on the local machine as part of the JSDK environment )
see http://java.sun.com/products/servlet/
The first step is to place the following class files and the 'encoder' directory in your Servlet Engines class file directory. For Tomcat this is usually /WEB-INF/classes/ and for the default setup of the JSDK environment this is the /examples/ directory.
linecharts.class
LineGraphServlet.class
encoder
( both these classes can be found in the Servlet directory ).
Notes :
Step 2 - Set up the Configuration data.
The line graph servlet provides the following two options for inputting the configuration data.
a) Configuration File.
The servlet will read all the configuration parameters from a specified file. To use this option incorporate the url of the configuration file into the the IMG tag (see Step 4).The "lineprops.txt" file contained in this directory is an example file containing the configuration data ( click here to view the example file ). As you will see from the example file each property is specified on a name, value basis. The first 20 character positions of each line represent the property name and position 21 onwards the value. (Also note that comments may be added to this file by placing "<!--" at the beginning of a line.).
Adjust the property values to specify the characteristics of the line graph and then place this file in the same directory as your web page.For a full description of each property please see the "Configuration Options and Parameters".
b) Server Side process
This option allows the line graph servlet to obtain all the configuration data from a server side application. The server side script should be designed to output the configuration data in the same format as the file in option a) above (ie. first 20 character positions of each line specify the parameter name, whilst positions 21 onwards specify the value).As with the previous option the URL of the server side process is specified in the <IMG> tag of your HTML page (see Step 4).
For an example script see LineConfigServlet.java in the ServerTemplateScripts directory.
For most implementations supplying the configuration data from a data file will be the most efficient, however supplying this data via a server side script is useful where you wish to hold this data in a database. A server side script would then be used to read the config data from the database and then supply to the servlet at runtime.
Step 3 - Set up the line graph data
As with the configuration data there are three options for supplying the line data to the applet,
a) Data File.
The servlet will read all the line data from a specified file. To use this option incorporate the url of the configuration file into the the IMG tag (see Step 4).The "linedata.txt" file contained in this directory is an example file containing the line data ( click here to view the example file ). As you will see from the example file each piece of data is specified on a name, value basis. The first 20 character positions of each line represent the data name (specifying the series and order) and position 21 onwards the value. (Also note that comments may be added to this file by placing "<!--" at the beginning of a line.).
Simply create a similar file adding your line data in the values. For a full explanation of this file please see the "Retrieving Data from Files" under the "Data and Configuration" section ( or click here).b) Server Side process
This option is the most powerful and gives the servlet the ability to retrieve data from databases. This method involves specifying a server side script in the <IMG> tag of the html page (see Step 4) which in turn returns the data to the graph servlet, giving enormous flexibility for data acquisition. The server side script can be constructed in the language of your choice and as such can be written to acquire data from the widest variety of sources, multiple databases etc.To instruct the servlet to retrieve data from a server side script simply add the URL of your server side script into the <IMG> tag of the HTML page (see Step 4). The server side script should be designed to output the data in the same format as the file in option a) above (ie. first 20 character positions of each line specify the data name, whilst positions 21 onwards specify the value).
For an example script see LineDataServlet.java in the ServerTemplateScripts directory.
For a full description of constructing a server side script which retrieves data from a database see the section "Connecting the Graph to a database" under the "Data and Configuration" section ( or click here).
Step 4 - Incorporate the Servlet IMG tag into your HTML page.
The final step is to incorporate the graph into your HTML page. This is done via the standard html <IMG> tag.
<img src="[ServletEngineURL]/LineGraphServlet?config=[URLconfigFile]&data=[URLdataFile]" width="500" height="420">
Where,
[ServletEngineURL] should be replaced with the url for your servlet engine. If running ServletRunner on your local machine this would be, http://localhost:8080/servlet/
[URLconfigFile] should be replaced with the URL to either a Configuration file or server side process.
[URLdataFile] should be replaced with he URL to either a Data file or server side process.
For example if we have the following,
Servlet Engine URL = http://www.jpowered.com/servlet/
Configuration File URl = http://www.jpowered.com/line_graph/config.txt
Data Servlet = dataservlet.class
producing a graph image of 400 pixels by 300 pixels, we would incorporate the following <IMG> tag into our html page,
eg.
<img src="http://www.jpowered.com/servlet/LineGraphServlet?
config=http://www.jpowered.com/line_graph/config.txt&
data=http://www.jpowered.com/siriusjava/servlet/dataservlet" width="400" height="300">
If experience any difficulties implementing then please do not hesitate to contact us at,
support@jpowered.com