Understanding the JWaveJSPServlet
The JWaveJSPServlet receives requests from JSP pages and passes them on to PV‑WAVE through standard JWAVE methods. Results from PV‑WAVE are passed back through the servlet to a reply JSP page, which displays the results in HTML format on the client.
This section discusses the JWaveJSPServlet and its related pieces: JSP pages and JWAVE wrappers.
note | The source code for the JWaveJSPServlet is provided with your JWAVE installation in: RW_DIR/classes/com/visualnumerics/servlet. |
JSP Files
JSP files are basically HTML documents with special tags that invoke the JWaveJSPServlet in response to submitting a form or clicking on a plot. Result JSP files include tags that are filled in by the JWaveJSPServlet with content from the server-side PV‑WAVE process.
JWAVE Wrappers
JWAVE wrappers are passed the following kinds of data from the client through the JSP engine:
Fields from HTML forms (including hidden fields used to specify the JWAVE wrapper, a PV‑WAVE session ID, and others).
Data coordinates of where a user clicked in an image map.
The JWAVE wrapper code contains all of the application logic. Data is accessed, manipulated, and numerical and graphical results are produced.
The wrappers use utility routines to help package and return graphics and tables. These utilities are discussed in
"Writing the JWAVE Wrappers".
Inside the JWaveJSPServlet: GET Requests, POST Requests, and the JWaveImageManager
The JWaveJSPServlet handles GET and POST requests. Typically, a GET request is used to retrieve an image that has been stored by the JWaveImageManager, or to return it directly to the client. For example, an IMG SRC command in HTML makes a GET request to get an image. A POST request is made when the client needs to send parameters and data to the server for processing. For example, a POST request is typically made when the user fills in a form and clicks the SUBMIT button.
The POST Request
When the JWaveJSPServlet receives a POST request, the doPost method is called. This method retrieves the posted parameters from the request object and calls the callWave method. The callWave method handles most of the JWAVE work, including making a connection to PV‑WAVE, passing the parameters to PV‑WAVE, executing the JWAVE wrapper, retrieving the results from PV‑WAVE, and dispatching the results back to the client (by forwarding the response to another JSP page).
Graphical results are identified in the doPost method and registered (stored) in the JWaveImageManager. The JWaveImageManager contains a small number of public methods. The methods that are used in the doPost method are:
public String registerImages(JWaveExecute jexecute, String imageName)
public void setFormat(String encodeformat)
public void setTimeout(int seconds)
public String getUname()
The registerImages method is used to store a named image in the
JWaveImageManager. As explained previously, a URL that points to the stored image is forwarded from the servlet to a JSP page that the client displays. The URL is embedded in an IMG SRC command in the HTML page that is sent to the client, enabling the client to retrieve and display the stored image.
Use the setFormat method to set the image format. For example, PNG is a commonly used format for delivering images over the Internet.
The setTimeout method allows you to configure how much time a graphic can be stored on the server before it is deleted and becomes a candidate for garbage collection.
GET Request
The JWaveJSPServlet also has a doGet method. This method is called whenever an image is requested by the client. Typically, the client requests an image when it displays an HTML page containing an IMG SRC command.
The doGet method calls the JWaveImageManager method processRequest:
public boolean processRequest(HttpServletRequest req,
HttpServletResponse res, String uname)
This method retrieves the image that is specified in the Request object (a URL plus a unique filename) and streams it back to the client.
Version 3.6
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.