11.2. JavaServer Pages (JSP)

11.2.1. Introduction

JavaServer Pages allow the separation of the dynamic content from the static HTML. JSPs allow HTML to be written in the traditional manner and then the code for the dynamic content is enclosed within the HTML within special tags, which usually start with <% and end with %>

The JSPs can be placed along with regular HTML files and look like HTML files in many ways. However, whenever a JSP is run, the page gets converted to a normal servlet while the static HTML is printed.

JavaServer Pages is basically an extension of the Servlet technology. However, there is one very big advantage in using JSPs. JavaServer Pages technology separates the user interface from content generation enabling designers to change the overall page layout without altering the underlying dynamic content.

EspressChart provides a few JSP examples. Here, we will show you how to run the JSP example with JSWDK. The example we will be looking at has been modified from the datafile servlet example and is located under EspressChart/help/examples/jsp/Chart. This example can also be used as a guide to run the other JSP examples as well as your own JSP code.

11.2.2. Running Under

11.2.2.1. Apache Tomcat

  • Please include EspressAPI.jar, ExportLib.jar and servlet.jar in the classpath. For instance,

    set classpath=c:\netscape\suitespot\docs\espresschart\lib\EspressAPI.jar; c:\netscape\suitespot\docs\espresschart\lib\ExportLib.jar;
    c:\tomcat\common\lib\servlet.jar;.
  • Create a chart subdirectory under webapps\examples\jsp\. Therefore, if Tomcat is installed under c:\, you now have a new directory c:\tomcat\webapps\examples\jsp\chart

  • Copy ExportChart.jsp, ExportChartResponse.jsp and error.jsp to the examples/jsp/chart directory

  • Create another directory, also called chart under the tomcat\webapps directory. Thus, you now have c:\tomcat\webapps\chart

  • Place the file CreateChart.java in the tomcat\webapps\chart directory. Next, modify the URL in the getFileLocation() by replacing http://yourMachineName/EspressChart to the correct URL. Suppose that your machine name is Mach1 and you have installed EspressChart under the Web server directory. Then you specify http://Mach1/EspressChart as the URL for getFileLocation()

  • Compile CreateChart.java. CreateChart.class should now exist in the same directory

  • Start the Tomcat server and start the EspressManager

  • Open a web browser and go to http://yourMachineName:8080/examples/jsp/chart/ExportChart.jsp (just substitute your actual machine name for yourMachineName)

  • Specify the options that you want and then click submit to get a chart in return.

11.2.2.2. WebSphere

  • Add EspressAPI and ExportLib.jar to the Dependent Classpath under the node (usually called by the machine name)

  • Click on the Wizards button on the toolbar (the last button) and select Create a Web Application

    • Enter Quadbase as the name of the web application. Make sure to uncheck the Enable File Servlet option, check Server Servlet by classname, and click on Next

    • Choose Default Servlet Engine as the node (keep expanding the tree till can you select the Default Servlet Engine) and click on Next

    • Change the Web Application Web Path to /Quadbase and click on Next

    • Add EspressAPI.jar and ExportLib.jar in separate lines to the Classpath and click on Finish

  • Restart the Default Server

  • Create a directory under your web server's document root called Quadbase and move the .jsp files and the java file there.

  • Modify CreateChart.java to

    • remove (or comment out) the package and

    • to replace the export command with

      chart.export(QbChart.JPEG, "<Absolute path to location of web server document root>/EspressChart/temp", 500, 400);
  • Modify the .jsp files to replace chart.CreateChart with CreateChart

  • Create a directory under your web server's document root called EspressChart

  • Start your browser and open http://<machine name>/Quadbase/ExportChart.jsp . Input the parameters and click on the button to get the chart