The typical Web
page contains embedded graphic images. This is easy to do in static
pages. To your static HTML, add an IMG tag, for example:
<IMG SRC="mykids.gif">
In a dynamic environment such as the Application Dispatcher,
the value for the SRC parameter must be a URL that invokes the Application
Broker. For example, inserting the following HTML code in a static
HTML page causes the sample graphics program to be run when the Web
browser loads the image:
<IMG SRC="/cgi-bin/broker?_service=default&_program=sample.webgraph.sas">
Programs called from
an IMG tag must respond with a content type of image/gif or image/jpeg.
You can add multiple parameters to this type of URL to make your graphics
program output more flexible and customizable. Each dynamic image
tag in your HTML page represents a separate request to the Application
Dispatcher and a separate program execution. It is important to keep
that in mind when you design your application. You might want to show
only one or just a few graphics on each page. That reduces the demand
on your Application Server.
Sometimes, you might be generating a dynamic
HTML page, and you want that dynamic page to contain one or more embedded
graphics that are also dynamic. One way to accomplish this is to use
the
Output Delivery System (ODS). Using ODS is convenient, because it lets you run procedures
that produce HTML and graphics within a single Application Dispatcher
program.
If you choose not to use ODS, you must have separate programs for
producing HTML and graphics. The first program that is called produces
the HTML page by writing to _WEBOUT. At the appropriate place in the
HTML source code, the first program writes an image tag that calls
the second program -- the program that produces the graphics. By using
the concepts outlined in
Data Passing and Program Chaining, the first program passes any name/value pair data to the second
program. Because the image tag is not an HTML form, you cannot use
hidden fields to pass the name/value pairs. You must encode them in
the query string of the URL that you generate for the SRC parameter.
Most of the time your
embedded graphics represent some underlying data. If that underlying
data changes, you expect the Web browser to display a new picture.
Note: Unfortunately, there is a serious defect in some Web
browsers that prevents the new graphic image from being displayed.
This is not a defect in
SAS/IntrNet software. Web browsers that exhibit
this defect load the URL, which causes the Application Dispatcher
program to execute and deliver a new image; but the old, cached image
is displayed. When the user arrives at the page by selecting a hyperlink,
a favorite, or a bookmark, or submits a form, an old image might be
seen. Click REFRESH or RELOAD in the Web browser to display the new
image. Unfortunately, sending the graphic image by using the Expires
or the Pragma: no-cache HTTP headers does not fix this problem.
One solution to this
problem is to add a caption to your embedded graphics that tells the
user to reload the page for the most up-to-date graphic. If your data
does not change too quickly, you might not need this caption. The
best solution is to trick the Web browser into not using a cached
image. You can do this by generating a unique URL every time the program
is executed. Because HTML files and images are cached according to
their URLs, the Web browser never has an old image that matches the
unique URL that the program generates.
To create
a unique URL, generate the SRC= URL string that you need and append
to the end of the URL a name/value pair that has a value of the current
SAS datetime, as shown in this example.
data _null_;
file _webout;
/*store broker path in data step variable*/
url=symget('_url');
/*store current service name*/
service=symget('_service');
/*use current program library so that this
application can be easily moved to another library*/
pgmlib=symget('_pgmlib');
program=compress(pgmlib)||'.graphit.sas';
/*create partial URL*/
src=trim(left(url))||'?_service='||trim(left(service))||
'&_program='||trim(left(program));
/*the above URL is enough to embed the graphic but a
unique string must be added to avoid incorrect caching*/
nocache=datetime();
src=src||'&nocache='||trim(left(nocache));
/*write out image tag*/
put '<IMG SRC="' src +(-1) '">';
run;
Each time this code
is executed, a different datetime value is returned. This process
results in a unique URL. The NOCACHE parameter is not used by the
graphics program because its only purpose is to trick the Web browser
into not using its cache.
Note: On some systems, it might
be better to call one of the SAS random functions instead of datetime.
If your system is fast and you make repeated, close calls to the datetime
function, it is possible to get the same value returned.