Invoking Net.Data with a Macro (Macro Request)

A client browser invokes Net.Data by sending a request in the form of a URL. This section shows you how to invoke Net.Data by specifying a macro in the URL request.

The request sent to Net.Data has the following form.

http://server/Net.Data_invocation_path/filename/block[?name=val&...]

Parameters:

server
Specifies the name and pathof the Web server. If the server is the local server, you can omit the server name and use a relative URL.

Net.Data_invocation_path
The path and filename of the Net.Data executable file, servlet class, DLL, or shared library. For example, /cgi-bin/db2www/.

filename
Specifies the name of the Net.Data macro file. Net.Data searches for and tries to match this file name with the path statements defined in the MACRO_PATH initialization path variable. See MACRO_PATH for more information.

block
Specifies the name of the HTML block in the referenced Net.Data macro.

?name=val&...
Specifies one or more optional parameters passed to Net.Data.

You specify this URL directly in your browser. Or, you can use it in an HTML link or build it using a form as follows:

Parameters:

method
Specifies the HTML method used with the form.

URL
Specifies the URL used to run the Net.Data macro, the parameters of which are described above.

Examples

The following examples demonstrate the different methods of invoking Net.Data.

Example 1: Invoking Net.Data using an HTML link:

<a href="http://server/cgi-bin/db2www/myMacro.d2w/report">
.
.
.
</a>
 

Example 2: Invoking Net.Data using a form

<form method=post
 action="http://server/cgi-bin/db2www/myMacro.d2w/report">
.
.
.
</form>
 

The following sections describe HTML links and forms and more about how to invoke Net.Data with them:

HTML Links

If you are authoring a Web page, you can create an HTML link that results in the execution of an HTML block. When a user at a browser clicks on a text or image that is defined as an HTML link, Net.Data executes the HTML block within the macro.

To create an HTML link, use the HTML <a> tag. Decide which text or graphic you want to use as your hyperlink to the Net.Data macro, then surround it by the <a> and </a> tags. In the HREF attribute of the <a> tag, specify the macro and the HTML block.

The following example shows a link that results in the execution of an SQL query when a user selects the text "List all monitors" on a Web page.

<a href="http://server/cgi-bin/db2www/listA.d2w/report">
List all monitors</a>

Clicking on the link calls a macro named listA.d2w, which has an HTML block named "report", as in the following example:

%DEFINE DATABASE="MNS97"
 
 
%FUNCTION(DTW_SQL) myQuery(){
SELECT MODNO, COST, DESCRIP FROM EQPTABLE
WHERE TYPE='MONITOR'
%}
 
%HTML(report){
@myQuery()
%}

The query returns a table that contains model number, cost, and description information for each monitor that is described within the EQPTABLE table. This example displays the results of the query by generating a default report. See Report Blocks for information on how you can customize your reports using a REPORT block.

HTML Forms

You can dynamically customize the execution of your Net.Data macros using HTML forms. Forms allow users to provide input values that can affect the execution of the macro and the contents of the Web page that Net.Data builds.

The following example builds on the monitor list example in HTML Links by letting users at a browser use a simple HTML form to select the type of product for which information will be displayed.

<h1>Hardware Query Form</h1>
<hr>
<form method=post action="/cgi-bin/db2www/equiplst.d2w/report">
<p>What type of hardware do you want to see?</p>
<menu>
<li><input type="radio" name="hdware" value="mon" checked /> Monitors</li>
<li><input type="radio" name="hdware" value="pnt" /> Pointing devices</li>
<li><input type="radio" name="hdware" value="prt" /> Printers</li>
<li><input type="radio" name="hdware" value="scn" /> Scanners</li>
</menu>
 
<input type="submit" value="submit" />
</form>
 

After the user at the browser makes a selection and clicks on the Submit button, the Web server processes the ACTION parameter of the FORM tag, which invokes Net.Data. Net.Data then executes the HTML report block in the equiplst.d2w macro:

%DEFINE DATABASE="MNS97"
 
 %FUNCTION(DTW_SQL) myQuery(){
SELECT MODNO, COST, DESCRIP FROM EQPTABLE
WHERE TYPE='$(hdware)'
%REPORT{
<h3>Here is the list you requested</h3>
%ROW{
<hr>
$(N1): $(V1), $(N2): $(V2)
<p>$(N3): $(V3)
%}
%}
%}
 
%HTML(report){
@myQuery()
%}

In the above example, the value of TYPE=$(hdware) in the SQL statement is taken from the HTML form input. See Net.Data Reference for a detailed description of the variables that are used in the ROW block.

An input type that is given special treatment by Net.Data is the FILE input type. With this input type, users can upload a file to the server, which can be further processed by Net.Data or any other application on the server.

Net.Data does not perform any conversion on the uploaded files, it is treated as binary data. The uploaded files are stored in the directory specified in DTW_UPLOAD_DIR and are given a unique name, determined using the following rules:

Syntax:

MacroFileName + '.' + FormVarName + '.' + UniqueIdentifier + '.' + FormFileName

MacroFileName
The name of the macro handling the request (the one called in the form). Only the filename is used, not the complete path.

FormVarName
The name of the variable used to identify the file in the form.

UniqueIdentifier
A string used to ensure uniqueness. This string is constructed differently depending upon the Net.Data platform. On OS/400, for example, the following method is used:
YYYYMMDDHHMMSSCCC + '-' + PID + '-' + TID
 

where:

YYYY = year
MM   = month
DD   = day
HH   = hour (00-23)
SS   = seconds
CCC  = milliseconds
PID  = process ID
TID  = thread ID
 

Example:

First, set DTW_UPLOAD_DIR in the Net.Data initialization file:

DTW_UPLOAD_DIR /home/http/pub/upload

Then construct a form that invokes a macro and passes the filename and file as a parameter:

<form method="post" enctype="multipart/form-data"
      action="/netdatadev/form.dtw/report">
  <input type="text" name="name"  value="john doe" />Enter name
  <input type="text" name="zipno" value="55901" />Enter number
  <input type="file" name="resume" value="myresume.txt" />Résumé
  <input type="submit" />
</form>

If a user were to submit the form, accepting the default values, the resulting file would appear on the server as something like this:

/home/http/pub/upload/form.dtw.resume.20000313112341275-6245-021.myresume.txt


[ Top of Page | Previous Page | Next Page | Index ]