Before you can create the JSP, get familiar with the Web page you plan to capture. You need to determine:
What is the page content?
How is the page rendered?
How do you extract the feature you plan to capture?
Then, write the JSP, keeping in mind the following guidelines:
The JSP is invoked either in Capture Mode or Run Time Mode. This is indicated by the request attribute “capture” which is a Boolean (“true” indicates “Capture Mode,” and “false” indicates “Run Time Mode”).
When executing in Capture Mode, the JSP is responsible for returning a list of possible captures. This list is returned as a Java Vector object in the request attribute “allkeys.”
Each element of the Vector is a capture “tag” or “name.” The JSP can use any naming convention it chooses, but if the tag or name starts with “grid,” it indicates to UA that the captured element is a grid, and will be subject to grid rules processing.
At run time, UA presents the tag or name of the capture that is required in the request attribute “key” to the JSP. The JSP is then responsible for returning the HTML snippet for this requested tag. This is just returned as JSP output (see the example). In order to extract the correct HTML snippet, the JSP needs access to the HTML of the complete target page, and this is available through the request attribute “html”. Clearly the JSP can process this HTML in any fashion it chooses, and construct output HTML as it thinks fit. But remember, if the tag starts with the string “grid,” it must be an HTML table amenable to grid rules processing.
Useful JSP request attributes:
capture – whether capture or playback
html – HTML content
url – URL for HTML
params – any parameters supplied to the JSP
key – key to match (run time only)
Attributes JSP returns:
allkeys – list of all keys (capture time only)
HTML content in runtime
Other JSP attributes the JSP can make use of:
conextID – ConextID value used to link applications together
sessionID – current Session ID
resourceID – the RID associated with playback
bindings – parameters used to play back the application
Following is a simple, JSP sample:
1:<% 2: Boolean capture = (Boolean)request.getAttribute("capture"); 3: String html = (String)request.getAttribute("html"); 4: Hashtable params = (Hashtable) request.getAttribute("params"); 5: 6: if (capture.booleanValue()) 7: { 8: // capture time ... 9: Vector allkeys = new Vector(); 10: // return 3 keys ... 11: allkeys.addElement("grid:1"); // a grid key 12: allkeys.addElement("grid:2"); // a grid key 13: allkeys.addElement("nongrid:3"); // a non-grid key 14: request.setAttribute("allkeys", allkeys); 15: return; 16: } 17: else 18: { 19: // run time ... 20: String key = (String)request.getAttribute("key"); 21: String extractHtml = null; 22: if (key.equals("grid:1")) 23: { 24: extractHtml = "<table><tr><th>Col 1</th><th>Col 2</th></tr><tr><td>Col 1 val</td><td>Col 2 val</td></tr></table>"; 25: } 26: else if (key.equals("grid:2")) 27: { 28: extractHtml = "<table><tr><th>Col 1</th><th>Col 2</th><th>Col 3</th></tr><tr><td>Col 1 val</td><td>Col 2 val</td><td>Col 3 val</td></tr></table>"; 30: } 31: else if (key.equals("nongrid:3"))32: { 33: extractHtml = "<p>Some content ....</p>"; 34: } 35: else 36: { 37: // shouldn't happen ... 38: extractHtml = "<table><tr><th>Error</th></tr><tr><td>Bad key: "+key+"</td></tr></table>"; 39: } 40:%> 41:<%=extractHtml%> 42:<% 43: } 44:%>