Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > 71d40963b505df4524269198e237b3e3 > files > 984

virtuoso-opensource-doc-6.1.4-2.fc14.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
 <head profile="http://internetalchemy.org/2003/02/profile">
  <link rel="foaf" type="application/rdf+xml" title="FOAF" href="http://www.openlinksw.com/dataspace/uda/about.rdf" />
  <link rel="schema.dc" href="http://purl.org/dc/elements/1.1/" />
  <meta name="dc.title" content="12. Web Application Development" />
  <meta name="dc.subject" content="12. Web Application Development" />
  <meta name="dc.creator" content="OpenLink Software Documentation Team ;&#10;" />
  <meta name="dc.copyright" content="OpenLink Software, 1999 - 2009" />
  <link rel="top" href="index.html" title="OpenLink Virtuoso Universal Server: Documentation" />
  <link rel="search" href="/doc/adv_search.vspx" title="Search OpenLink Virtuoso Universal Server: Documentation" />
  <link rel="parent" href="webappdevelopment.html" title="Chapter Contents" />
  <link rel="prev" href="wsacl.html" title="Web Services ACL (Access Control List)" />
  <link rel="next" href="vspx.html" title="Virtuoso Server Pages for XML (VSPX)" />
  <link rel="shortcut icon" href="../images/misc/favicon.ico" type="image/x-icon" />
  <link rel="stylesheet" type="text/css" href="doc.css" />
  <link rel="stylesheet" type="text/css" href="/doc/translation.css" />
  <title>12. Web Application Development</title>
  <meta http-equiv="Content-Type" content="text/xhtml; charset=UTF-8" />
  <meta name="author" content="OpenLink Software Documentation Team ;&#10;" />
  <meta name="copyright" content="OpenLink Software, 1999 - 2009" />
  <meta name="keywords" content="" />
  <meta name="GENERATOR" content="OpenLink XSLT Team" />
 </head>
 <body>
  <div id="header">
    <a name="vsp1" />
    <img src="../images/misc/logo.jpg" alt="" />
    <h1>12. Web Application Development</h1>
  </div>
  <div id="navbartop">
   <div>
      <a class="link" href="webappdevelopment.html">Chapter Contents</a> | <a class="link" href="wsacl.html" title="Web Services ACL (Access Control List)">Prev</a> | <a class="link" href="vspx.html" title="Virtuoso Server Pages for XML (VSPX)">Next</a>
   </div>
  </div>
  <div id="currenttoc">
   <form method="post" action="/doc/adv_search.vspx">
    <div class="search">Keyword Search: <br />
        <input type="text" name="q" /> <input type="submit" name="go" value="Go" />
    </div>
   </form>
   <div>
      <a href="http://www.openlinksw.com/">www.openlinksw.com</a>
   </div>
   <div>
      <a href="http://docs.openlinksw.com/">docs.openlinksw.com</a>
   </div>
    <br />
   <div>
      <a href="index.html">Book Home</a>
   </div>
    <br />
   <div>
      <a href="contents.html">Contents</a>
   </div>
   <div>
      <a href="preface.html">Preface</a>
   </div>
    <br />
   <div class="selected">
      <a href="webappdevelopment.html">Web Application Development</a>
   </div>
    <br />
   <div>
      <a href="webserver.html">The HTTP Server</a>
   </div>
   <div>
      <a href="wsacl.html">Web Services ACL (Access Control List)</a>
   </div>
   <div class="selected">
      <a href="vsp1.html">Virtuoso Server Pages (VSP)</a>
    <div>
        <a href="#vspmarkup" title="VSP Markup &amp; Basic Functions">VSP Markup &amp; Basic Functions</a>
        <a href="#accessrequestinfo" title="Access Request Information">Access Request Information</a>
        <a href="#errorsinpage" title="Errors in Page Procedures">Errors in Page Procedures</a>
        <a href="#inlinefile" title="/INLINEFILE HTTP Server Pseudo-Directory">/INLINEFILE HTTP Server Pseudo-Directory</a>
        <a href="#furthervsp" title="Beyond Basics">Beyond Basics</a>
        <a href="#longhttptrans" title="Long HTTP Transactions">Long HTTP Transactions</a>
        <a href="#httpchunkedoutput" title="Using chunked encoding in HTTP 1.1">Using chunked encoding in HTTP 1.1</a>
        <a href="#mksimpledynapages" title="Making Simple Dynamic Web Pages">Making Simple Dynamic Web Pages</a>
        <a href="#xmlthtmloutmd" title="Generation of non-HTML output">Generation of non-HTML output</a>
        <a href="#xmlthtmloutmd" title="Post VSP XSLT Transformation Mode">Post VSP XSLT Transformation Mode</a>
        <a href="#xmlforproducingvsp" title="XML &amp; XSLT Generated VSP Pages">XML &amp; XSLT Generated VSP Pages</a>
    </div>
   </div>
   <div>
      <a href="vspx.html">Virtuoso Server Pages for XML (VSPX)</a>
   </div>
   <div>
      <a href="rthwritaspxapps.html">Deploying ASP.Net Web Applications</a>
   </div>
   <div>
      <a href="asmxhosting.html">ASMX Web Service Hosting</a>
   </div>
   <div>
      <a href="blogger.html">Blogging &amp; Weblogs</a>
   </div>
   <div>
      <a href="servphpext.html">Deploying PHP Applications</a>
   </div>
   <div>
      <a href="rthjsp.html">Deploying JSP Applications</a>
   </div>
   <div>
      <a href="perlhosting.html">Perl Hosting</a>
   </div>
   <div>
      <a href="pythonhosting.html">Python Hosting</a>
   </div>
   <div>
      <a href="rubyhosting.html">Ruby Hosting</a>
   </div>
    <br />
  </div>
  <div id="text">
    <a name="vsp1" />
    <h2>12.3. Virtuoso Server Pages (VSP)</h2>

<p>The Virtuoso Server Pages subsystem is an integral part of the Virtuoso server.
A VSP page is a file system or DAV resident resource that contains Virtuoso/PL code intermixed with HTML or other static content.</p>

  <table class="figure" border="0" cellpadding="0" cellspacing="0">
    <tr>
     <td>
          <img alt="VSP Conceptual Diagram" src="../images/vspconcept.jpg" />
     </td>
    </tr>
    <tr>
        <td>Figure: 12.3.1. VSP Conceptual Diagram</td>
    </tr>
    </table>

<p>Virtuoso can serve Web pages to HTTP 1.0 and HTTP 1.1 clients.  The
HTTP document root is set by the ServerRoot parameter in the [HTTPServer]
section of the Virtuoso INI file.  By default this is set to <span class="computeroutput">vsp</span>
sub-directory of the installation.  If this parameter is not set, then the default
document root will be the server&#39;s working directory.  </p>

<div class="formalpara">
      <strong>Executing VSP Pages</strong>
<p>Directories under the ServerRoot directory, including the root itself are
not automatically allowed to execute dynamic pages such as VSP.  A virtual
directory must first be created with an appropriate VSP user assigned to
permit execution of dynamic pages. After this, Virtuoso will execute files
with a &quot;<span class="computeroutput">.vsp</span>&quot; extension as a VSP page.]
</p>
    </div>

<div class="formalpara">
      <strong>The VSP Stored Procedure</strong>
<p>Each VSP page constitutes a Virtuoso stored procedure named after the
URI of the page by taking the URI and pre-pending the WS.WS. qualifier and owner.
Hence the page <span class="computeroutput">/test.vsp</span> becomes the procedure
<span class="computeroutput">&quot;WS&quot;.&quot;WS&quot;.&quot;/test.vsp&quot;</span>.  This is automatically performed
when a page is first requested.  Subsequent requests to the page will not
reference the file.  The VSP engine will check for changes in the
<span class="computeroutput">.vsp</span> source file before calling the
procedure and re-compile as required.
The <a href="">ws_proc_def()</a> SQL function
can be used to explicitly update the procedure if the .vsp file is changed.
</p>
    </div>

<a name="fp_httphandleclidisconnect" />
    <div class="formalpara">
      <strong>The VSP Transaction</strong>
<p>Each URL is executed in its own transaction.  All SQL statements in a page
procedure, whether on local or remote data, make up one transaction, unless
transaction control statements are explicitly used to divide the page into
multiple transactions.  If the page procedure returns through completing execution
or through a return statement or as a result of a &#39;no data found&#39; condition, the
transaction is implicitly committed.  If this commit fails, the output is discarded
and the error message indicating the commit failure is sent to the HTTP client.
If a VSP procedure returns as a result of an error the transaction is rolled
back and the output discarded.  The client gets the SQL error message as the
HTML body of the reply.  A VSP procedure can commit or roll back explicitly with
the <span class="computeroutput">commit work</span> or
<span class="computeroutput">rollback work</span> PL statements.
</p>
<p>If the client closes the connection to the server while server-side processing
    is taking place this will be detected by the server and the transaction will be
    eventually interrupted and rolled back in the same way as if an ODBC client
    had disconnected. To control the server reacting or not on the HTTP client
    disconnecting the SET HTTP_IGNORE_DISCONNECT = ON/OFF should be used.</p>
 </div>

<p>Each VSP page-procedure is called with three arguments:</p>

<ul>
      <li>
        <strong>path</strong> - the URI path of the VSP page itself.</li>
      <li>
        <strong>params</strong> - the parameters from a previous POST to the server.</li>
      <li>
        <strong>lines</strong> - the complete set of headers received from the calling client.</li>
    </ul>

<p>Each VSP procedure runs in a context that implicitly contains the
stream to the HTTP client.  The arguments of the VSP page procedure are
represented as arrays of strings. For example, GETing the URL: </p>

  <div>
      <pre class="programlisting">
http://www.test.net/x/y.vsp?arg1=1&amp;arg2=2
</pre>
    </div>
  <p>would cause the following arguments to be given to the page-procedure
  <span class="computeroutput">WS.WS./x/y.vsp</span>:</p>

  <div>
      <pre class="programlisting">
path     (&#39;x&#39;, &#39;y.vsp&#39;)
params   (&#39;arg1&#39;, &#39;1&#39;, &#39;arg2&#39;, &#39;2&#39;)
lines    (&#39;GET /x/y.vsp?arg1=1&amp;arg2=2 HTTP/1.1&#39;, &#39;Host: www.test.net&#39;, ...)
</pre>
    </div>

<p>Arrays are marked in parentheses with elements separated by commas.
The page procedure is called as a result of either a GET or POST request in
either HTTP/1.0 or HTTP/1.1. In the event of a POST request the params contains
the post data.</p>

<p>Virtuoso can be configured to proxy certain requests to another web
server.  This allows using another web server for running cgi-bin&#39;s, Java
servelets or other web server functions.  Virtuoso, however, is capable of
hosting many other dynamic engines also, such as PHP, JSP and ASP.Net.</p>

  <div class="tip">
      <div class="tiptitle">See Also:</div>
  <p>
        <a href="webserver.html#vspconf">HTTP Server Base Configuration</a>
      </p>
  <p>
        <a href="htmlconductorbar.html#httpvirtualdirs">Virtual Directory Administration UI</a>
      </p>
  <p>
        <a href="fn_vhost_define.html">vhost_define()</a>, <a href="fn_vhost_remove.html">vhost_remove()</a>
      </p>
  <p>
        <a href="webserver.html#virtproxy">Virtuoso as a Proxy</a>
      </p>
  </div>

<a name="vspmarkup" />
    <h3>12.3.2. VSP Markup &amp; Basic Functions</h3>

<p>All VSP specific markup is represented as a processing instruction (&lt;? ... ?&gt;).</p>

<div>
      <pre class="programlisting">
&lt;?vsp
  statement ;
  statement ;
  ...
 ?&gt;
</pre>
    </div>

<p>This markup introduces Virtuoso PL code to a VSP page, which otherwise
may normally contain HTML markup.  The code enclosed must begin
and end at a statement boundary but a compound statement may begin in one
&lt;?vsp tag and end in another.  Code outside of these blocks is ignored
by Virtuoso and placed directly on the HTTP stream to be sent to the client.</p>

<div class="tip">
      <div class="tiptitle">See Also:</div>
<p>The <a href="sqlprocedures.html">SQL Procedure Language Guide</a> chapter.</p>
    </div>

<p>Several functions exist to allow VSP code to send data to the HTTP stream.
They are basically the same but offer different escaping mechanisms to suit different purposes:</p>

<p>
      <a href="fn_http.html">http (in <span class="parameter">value</span>,  varchar, in <span class="parameter">stream</span> any);</a>
    </p>
<p>
      <a href="fn_http_value.html">http_value ( in <span class="parameter">value</span>,  any, in <span class="parameter">tag</span>,  varchar, in <span class="parameter">tag</span>,  varchar, in <span class="parameter">stream</span> any);</a>
    </p>
<p>
      <a href="fn_http_url.html">http_url ( in <span class="parameter">value</span>,  any, in <span class="parameter">tag</span>,  varchar, in <span class="parameter">stream</span> any);</a>
    </p>

<p>These functions output their <span class="computeroutput">value</span> argument
to the specified stream with varying escaping. The value argument may be any
scalar object, i.e. string, date or number and will automatically be cast to
varchar before further processing.</p>

<p>
      <span class="computeroutput">http()</span> will print out the contents of <span class="computeroutput">value</span>
cast to string without any modification.</p>

<p>
      <span class="computeroutput">http_value()</span> will use HTML escapes such that
&#39;<span class="computeroutput">&lt;</span>&#39; will be output as
&#39;<span class="computeroutput">&amp;lt;</span>&#39;.</p>

<p>The <span class="computeroutput">http_url()</span> function will use URL escapes
such that &#39;+&#39; replaces spaces and hex escapes like %25 will replace &#39;%&#39;.
If <span class="computeroutput">http_value()</span> gets an XML entity returned by a
path expression it outputs the serialization of the entity, including children.
This is not the string value since this has the entity start and end tags and
other markup.  The tag argument allows specifying a tag in which the value
is to be enclosed.  A non-string value, e.g. 0 or null will cause no tag to be
put around the value.</p>

<p>The stream argument may be omitted, in which case it defaults to the HTTP
client of the calling procedure.  If present, a value of integer 0 will mean the
http client.  If non-0 the value must be an object returned by
<a href="fn_string_output.html">string_output()</a>.</p>

<p>These HTTP functions are commonly combined with <span class="computeroutput">sprintf()</span>
which allows string composition based on a template.  When
using <a href="fn_sprintf.html">sprintf()</a> to compose data
to send to the user agent the %V and %U letters can be used to introduce escapes
similar to http_value and http_url, respectively.
</p>

<a name="ex_httpfunctions" />
    <div class="example">
      <div class="exampletitle">HTTP Functions</div>
<div>
        <pre class="programlisting">
http (&#39; % &lt;b&gt;&#39;)          &#39; % &lt;b&gt;&#39;
http_value (&#39; % &lt;b&gt;&#39;)    &#39; % &amp;lt;b&amp;gt;&#39;
http_url (&#39; % &lt;b&gt;&#39;)      &#39;+%25+&lt;b&gt;&#39;
http_value (12, &#39;li&#39;)    &#39;&lt;li&gt;12&lt;/li&gt;&#39;
</pre>
      </div>
</div>

<a name="vspmarkupshort" />
    <h4>12.3.2.1. Markup Short-hands</h4>

<p>VSP markup short-hands exist for the <span class="computeroutput">http_value()</span> and
<span class="computeroutput">http_url()</span> functions to perform the same task outside of
a VSP code block.  This can improve readability of VSP pages.</p>

<div>
      <pre class="programlisting">
&lt;?= expression ?&gt;  equiv.  http_value()
</pre>
    </div>
  <div>
      <pre class="programlisting">
&lt;?/ expression ?&gt;  equiv.  http_url()
</pre>
    </div>

<p>These markups are shorthand for substituting values of expressions into
the output.  The <span class="computeroutput">&lt;?= </span>tag accepts a SQL
expression and casts the value into a string, which is sent to the output.  The
<span class="computeroutput">&lt;?/ </span> markup sends the value of the
expression to the client with HTTP URL escapes.</p>

<a name="vspmkup" />
    <div class="example">
      <div class="exampletitle">VSP Markup</div>
<p>Here is a very simple example of making a two column HTML table
from the results of a &quot;select&quot; SQL statement.  First using normal functions:</p>
<div>
        <pre class="programlisting">
&lt;html&gt;
&lt;h2&gt;List of Users&lt;/h2&gt;
&lt;table&gt;
&lt;?vsp
  for (select u_name, u_password from sys_users ) do {
    http(&#39;&lt;tr&gt;&lt;td&gt;&#39;);
    http (u_name);
    http(&#39;&lt;/td&gt;&lt;td&gt;&#39;);
    http (u_password);
    http(&#39;&lt;/td&gt;&lt;/tr&gt;&#39;);
  }
?&gt;
      &lt;/table&gt;
&lt;/html&gt;
</pre>
      </div>

<p>This fragment outputs a table of user names and passwords.  We have
chosen to not end the code block until the end of the result so we have repeatedly
used the <span class="computeroutput">http()</span> function to output parts of the table also.</p>

<p>Now the same code but including shorthands:</p>

<div>
        <pre class="programlisting">
&lt;html&gt;
&lt;h2&gt;List of Users&lt;/h2&gt;
&lt;table&gt;
&lt;?vsp for (select u_name, u_password from sys_users ) do { ?&gt;
  &lt;tr&gt;
    &lt;td&gt;&lt;?=u_name ?&gt;&lt;/td&gt;
    &lt;td&gt;&lt;?=u_password ?&gt;&lt;/td&gt;&lt;/tr&gt;
      &lt;?vsp } ?&gt;
      &lt;/table&gt;
&lt;/html&gt;
</pre>
      </div>
</div>
<br />
<br />

<a name="accessrequestinfo" />
    <h3>12.3.3. Access Request Information</h3>

  <p>Request information, resulting from an HTTP POST, is available via
  the <span class="computeroutput">params</span> vector.  The params vector is always
  available for the purpose in a VSP context.  Similarly the <span class="computeroutput">lines</span>
  and <span class="computeroutput">path</span> vectors are available for the HTTP headers and
  URL path respectively.</p>

  <p>Parameters stored in the params vector are stored in keyword-value
  pairs, such that keywords are stored in the even elements, values in the odd
  numbered elements.  Vectors and arrays can be accessed using the
  <span class="computeroutput">aref()</span> and <span class="computeroutput">aset()</span> functions,
  however, the exact position of parameters is seldom known.  The
  <span class="computeroutput">get_keyword()</span> function can be used to return the value of a
  given parameter.  You can specify a default value to return in case the
  parameter you are looking for is not found.</p>

  <p>
      <span class="computeroutput">get_keyword (<span class="parameter">&#39;param_name&#39;</span>, , <span class="parameter">vector</span>,  [, <span class="parameter">opt_default_value&#39;</span>]);</span>
    </p>

  <p>If a default value other than &#39;&#39; (empty-string) is not required then a
  short-hand can be used instead.</p>

<div>
      <pre class="programlisting">{?&#39;param_name&#39;}</pre>
    </div>

<p>is equivalent to <span class="computeroutput">get_keyword (<span class="parameter">&#39;param_name&#39;</span>, , <span class="parameter">&#39;params&#39;</span>);</span>
    </p>



  <p>Since <span class="computeroutput">get_keyword()</span> returns only strings, you will
  find that <span class="computeroutput">cast</span>ing or conversion functions
  such as <span class="computeroutput">atoi()</span> are very useful here.</p>

  <a name="ex_usingparamsvector" />
    <div class="example">
      <div class="exampletitle">Reading the params Vector</div>
  <p>Consider retrieving the following page by means of the URL: </p>

  <div>
        <pre class="programlisting">
http://myvirtuoso/test.vsp?arg1=1&amp;arg2=test
</pre>
      </div>

<div>
        <pre class="programlisting">
&lt;html&gt;
 &lt;body&gt;
  &lt;h1&gt;Test Params&lt;/h1&gt;
  &lt;?vsp
  declare _arg1 integer; --   the underscore helps to differentiate from
  declare _arg2 varchar; --   the keyword name, whereas the variable names
  declare _arg3 varchar; --   help use remember which is which.

  _arg1 := atoi(get_keyword(&#39;arg1&#39;, params));
  _arg2 := {?&#39;arg2&#39;};
  _arg3 := get_keyword(&#39;arg3&#39;, params, &#39;was empty&#39;};

  ?&gt;
  &lt;p&gt;values returned:&lt;/p&gt;
  &lt;p&gt;arg1: &lt;?=_arg1?&gt;&lt;/p&gt;
  &lt;p&gt;arg2: &lt;?=_arg2?&gt;&lt;/p&gt;
  &lt;p&gt;arg3: &lt;?=_arg3?&gt;&lt;/p&gt;
 &lt;/body&gt;
&lt;/html&gt;
</pre>
      </div>
</div>

  <div class="tip">
      <div class="tiptitle">See Also:</div>
  <p>
        <a href="fn_get_keyword.html">get_keyword()</a>
      </p>
  <p>
        <a href="fn_atoi.html">atoi()</a>
      </p>
  <p>
        <a href="fn_aref.html">aref()</a>
      </p>
  <p>
        <a href="fn_aset.html">aset()</a>
      </p>
  <p>
        <a href="sqlrefDATATYPES.html#dtcasting">cast</a>
      </p>
    </div>

  <div class="note">
      <div class="notetitle">Note:</div>
    <p>Sometimes a POST can supply a large amount of data, such as from
    an &lt;INPUT type=&quot;file&quot;&gt;.  When the length of the parameter data
    exceeds 5,000,000 octets the result is stored as a string session in the
    params array.  In these cases the value should not be copied or converted
    to a string, it is likely to be truncated.  The value should be stored as a
    BLOB or an external file.  When processing possibly large input fields in a
    form either the fourth parameter to <span class="computeroutput">get_keyword()/get_keyword_ucase()</span>
    should be set to 1 or they should be accessed
    through <span class="computeroutput">aref_set_0()</span>.</p>
    </div>

<br />

<a name="errorsinpage" />
    <h3>12.3.4. Errors in Page Procedures</h3>
  <p>
VSP pages can declare handlers for errors using the normal handler declaration or whenever ... goto construct.
Any unhandled error causes the procedure to be terminated and the error
message to be sent to the HTTP client instead of the output.  Because terminating
the page output at an arbitrary point would probably result in not well formed output
all the output up to the point of the error is discarded.
</p>

<p>If the SQL state signalled with the error is VSPRT the output
generated up to the point where the error was signalled is sent as
such to the user agent.  This special SQL state is useful together
with the http_rewrite function for things like sending a redirect based
on a condition detected in the middle of page processing.  The
http_rewrite function will clear all output buffered so far and
signaling VSPRT will make sure that whatever output is generated
after http_rewrite goes unmodified to the user agent.</p>

<br />

<a name="inlinefile" />
    <h3>12.3.5. /INLINEFILE HTTP Server Pseudo-Directory</h3>

  <p>This pseudo directory provides a way for a VSP page to have full
  control over the data sent to the client user-agent, for example to send files to
  it and to handle the HTTP response attributes.</p>
  <p>URIs starting with
  /INLINEFILE are handled through a VSP procedure instead of
  being searched for in the HTTP root directory.  This special URI has the
  following syntax:</p>

<div>
      <pre class="programlisting">
/INLINEFILE/some_file_name?VSP=some_vsp&amp;arg1=x&amp;arg2=y.....
</pre>
    </div>

  <p>Upon receipt of such a URI, Virtuoso will execute the &quot;some_vsp&quot;
  VSP page with the parameters following the VSP parameter.  The VSP page
  can adjust the HTTP response header attributes using the
  <span class="computeroutput">http_header()</span> function to reflect the content of the
  HTTP body, such as specifying the encoding through &quot;Content-Encoding&quot; attribute,
  or a MIME type through &quot;Content-Type&quot; attribute).</p>

<a name="ex_inlinefile" />
    <div class="example">
      <div class="exampletitle">Using /INLINEFILE</div>
<p>Here is a simple example  for showing JPEG images stored in DAV.
The page will list the first ten images found in the DAV resources table as hyper-links.
Clicking on them will fetch the content and display using
/INLINEFILE.</p>

<div>
        <pre class="programlisting">
&lt;?vsp
  if ({?&#39;getfile&#39;} &lt;&gt; &#39;&#39;)
    {
      http_header (&#39;Content-type: image/jpg\t\n&#39;);         -- set the header to jpg
      declare image any;
      select RES_CONTENT into image from WS..SYS_DAV_RES
        where RES_ID = atoi({?&#39;id&#39;});                      -- download image from WebDAV
      http(image);                                         -- table and display
      return;
    }
  ?&gt;
&lt;html&gt;
 &lt;body&gt;
 &lt;h1&gt;Using /INLINEFILE to display images from the database&lt;/h1&gt;

 &lt;table&gt;
  &lt;tr&gt;
   &lt;td&gt;

&lt;?vsp for (select top 10 RES_ID, RES_NAME from WS..SYS_DAV_RES where right(RES_NAME, 3) = &#39;jpg&#39;) do {?&gt;
 &lt;a href=&quot;?id=&lt;?=RES_ID?&gt;&quot;&gt;&lt;?=RES_NAME?&gt;&lt;/a&gt;&lt;br&gt;
&lt;?vsp } ?&gt;

   &lt;/td&gt;
   &lt;td&gt;
    &lt;p&gt;&lt;img src=&quot;/INLINEFILE/picture.jpg?VSP=&lt;?/http_path()?&gt;&amp;getfile=yes&amp;id=&lt;?={?&#39;id&#39;}?&gt;&quot;&gt;&lt;/p&gt;
    &lt;p&gt;&lt;a href=&quot;/INLINEFILE/picture.jpg?VSP=&lt;?/http_path()?&gt;&amp;getfile=yes&amp;id=&lt;?/{?&#39;id&#39;}?&gt;&quot;&gt;download&lt;/a&gt;&lt;/p&gt;
   &lt;/td&gt;
  &lt;/tr&gt;
 &lt;/table&gt;
 &lt;/body&gt;
&lt;/html&gt;
</pre>
      </div>

<div class="note">
        <div class="notetitle">Note:</div>
  <p>Note the use of the <span class="computeroutput">http_path()</span> function to find the
  full path of the originating VSP file.</p>
  <p>Also note the call to <span class="computeroutput">http_header()</span> to set the appropriate
  content type for the returned data.  When Virtuoso retrieves files normally, it will
  consult the system table <span class="computeroutput">WS.WS.SYS_DAV_RES_TYPES</span>
  for types based on the file extension.  We do not need to refer to the table in our
  example because we are making sure that only JPEGs are being returned.</p>
  </div>
</div>

  <div class="tip">
      <div class="tiptitle">See Also:</div>
  <p>
        <a href="fn_http_header.html">http_header()</a>
      </p>
  <p>
        <a href="fn_http_path.html">http_path()</a>
      </p>
    </div>

<br />


<a name="furthervsp" />
    <h3>12.3.6. Beyond Basics</h3>

<p>All output from VSP page procedures is buffered into a local string
stream before being sent out.  This is done so as to support the HTTP/1.1 required
content length and to allow recovery from errors.</p>

<p>
      <a href="fn_http_rewrite.html">http_rewrite ( in <span class="parameter">stream</span> any);</a>
    </p>

  <p>This clears any previous output to the stream.  If the stream is
  omitted or 0 the stream is the HTTP client stream of the calling procedure.</p>

<p>
      <a href="fn_http_file.html">http_file ( in <span class="parameter">path</span> varchar);</a>
    </p>

  <p>This function sends a file to the HTTP client as a response to the
  current request.  Any other output that may have been generated by the calling
  procedure will be discarded and the contents of the file will be the exclusive
  response to the current HTTP request together with appropriate headers.
  The file will only be sent after the procedure handling the current HTTP
  request has returned.  The file name is thus not validated until the calling
  procedure has returned.</p>

<p>
      <a href="fn_http_get.html">http_get( in <span class="parameter">uri</span>,  varchar,
out <span class="parameter">headers</span> varchar);</a>
    </p>

  <p>This function retrieves the document specified by the URI by HTTP and
  returns the data of the response.  The header output parameter is set to be
  an array with an element for each line of the response&#39;s HTTP header.  Each
  line is a varchar object in the containing array.  The header parameter is optional.</p>

  <p>The URI is of the form <span class="computeroutput">host[:port]&lt;path&gt;</span>, e.g
  &#39;<span class="computeroutput">www.openlinksw.com:80/index.html</span>&#39;.  The
  port, if omitted, defaults to 80.  The data following the headers is not
  processed in any way.  No content transfer encodings are decoded but an
  eventual content transfer encoding header can be found in the header array.</p>

<p>
      <a href="fn_http_flush.html">http_flush();</a>
    </p>
  <p>This function generates a response header, flushes a stream and
  disconnects the client, however, the server will continue with the execution
  of the PL code in VSP page.  The final result will never be sent to the client.
  This is useful when a page makes a long transaction and we do not wish the
  client to wait until its end, which may result in a time-out.   Suppose we have the
  retrieval of news from many targets, each a thousand messages.  We start from
  a VSP page process, inside it we put into the internal stream (using http,
  http_value etc.) redirect code and call http_flush.  The client can read the
  response and go to a status page that can display number of messages retrieved,
  which may need refreshing a few times.</p>

  <p>
      <a href="fn_http_proxy.html">
 http_proxy (in <span class="parameter">host_and_port</span>,  varchar,
            in <span class="parameter">header_lines</span>,  any,
	    in <span class="parameter">post_parameters</span> any)</a>
    </p>

  <p>
The function http_proxy() is used to send request in header_lines and post_parameters
to the host_and_port, read the response and send it back to the client.
The http_proxy() function can be used inside a VSP page to send a request to
an external web server and automatically route the reply sent by this remote server
to the client of the VSP page calling http_proxy().
The output which can generated (with http functions, etc.) before and after http_proxy
is called will be discarded before sending the result of link retrieval to the user-agent.
</p>

<a name="virtpxy" />
    <div class="example">
      <div class="exampletitle">Virtuoso Proxy</div>

<div>
        <pre class="programlisting">
...
&lt;?vsp
  http (&#39;this never be displayed&#39;);
  http_proxy (&#39;www.foo.com&#39;, vector (&#39;GET / HTTP/1.0&#39;), NULL);
  http (&#39;and this also&#39;);
?&gt;
...
</pre>
      </div>
</div>

<a name="httpcharsettings" />
    <h4>12.3.6.1. Virtuoso HTTP Server Character Set Settings</h4>
  <p>When the HTTP server returns the HTTP header to the client it appends charset=xxxx to
the Content-Type: HTTP header fields.  This informs the client user agent, the web browser,
as to the character set of the content to be displayed correctly.  It uses the Web server
charset to correctly format values resulting from the <span class="computeroutput">http_value()</span> function
or the VSP equivalent &lt;?= ...&gt;.  Wide values and XML entities, resulting from any XML
processing functions like xpath_contains, get represented using
the &quot;HTML/XML transformation&quot;.</p>
  <p>The default web server charset is governed by the <strong>Charset</strong>
setting defined in the <a href="databaseadmsrv.html#VIRTINI">Virtuoso INI file</a>.  If no default
charset is specified then Virtuoso will use ISO-8859-1.</p>
  <p>The HTTP character set can be changed during an HTTP session using:
  <strong>set http_charset=&#39;charset_name&#39;;</strong>.</p>
  <p>The XSLT output encoding can also be specified to over ride the server
  default setting.</p>
<br />

<a name="sesmanvars" />
    <h4>12.3.6.2. Session Management and State Variables</h4>

  <p>
The Virtuoso HTTP session management consists of functions for session
variables manipulation and hooks for saving and restoring session variables.
</p>
  <p>Session management must be enable by setting the flag for persistent
  session variables in the virtual directory mapping.  Virtual directory mappings use
  the <strong>persistent_session_variables</strong> flag, which when
specified, session variables can be used in a post-process function to determine
if the session variables content must be stored on to the session table or not.
</p>
  <p>
The post-processing function hook can be any user-defined Virtuoso/PL procedure,
it will be executed every time after processing of the active page.
</p>

<div class="tip">
      <div class="tiptitle">See Also:</div>
<p>
        <a href="fn_connection_get.html">connection_get()</a>
      </p>
<p>
        <a href="fn_connection_set.html">connection_set()</a>
      </p>
<p>
        <a href="fn_connection_vars.html">connection_vars()</a>
      </p>
<p>
        <a href="fn_connection_vars_set.html">connection_vars_set()</a>
      </p>
<p>
        <a href="fn_connection_is_dirty.html">connection_is_dirty()</a>
      </p>
</div>

<br />



<br />

<a name="longhttptrans" />
    <h3>12.3.7. Long HTTP Transactions</h3>

  <p>Long running tasks may be invoked by web clients. In such a case,
  the server should return a page for the user agent much before the tasks&#39;s completion
  in order to provide feedback and avoid timeouts. Also the long running task should not be
  interrupted by the user agent disconnecting. The <span class="computeroutput">http_flush()</span> function will
  send the reply accumulated thus far to the user agent and then disconnect it.
  In effect, this is a generic mechanism for starting an asynchronous thread.</p>

  <p>Starting long running tasks may lead to denial of service.
  To prevent this we can use status and stop functions to check processes and
  kill them if necessary.</p>

  <p>We can retrieve the URL, client IP-address, and process status code
  for all currently running VSP requests, then use this information to isolate
  and eliminate a process.</p>

  <p>
      <a href="fn_http_pending_req.html">http_pending_req()</a>
  Lists the processes.</p>

  <p>
      <a href="fn_http_kill.html">http_kill()</a> can be used to kill them.</p>

<br />

<a name="httpchunkedoutput" />
    <h3>12.3.8. Using chunked encoding in HTTP 1.1</h3>

  <p>It is sometimes desirable to use the HTTP 1.1 chunked encoding to send
  data to HTTP clients. Examples of such include status pages or streaming
  applications. Note that the possibility of using chunked encoding depends on
  external factors such as whether the client browser supports chunked
  encoding. So a server page can request turning on the chunked encoding, but should
  handle the case should it not be available.</p>
  <p>Note that in order to successfully turn on the chunked encoding the
  page should not be using the <span class="computeroutput">http_xslt()</span>. Also
  all reply headers set by the <span class="computeroutput">http_header()</span> are silently
  ignored after the mode is set.</p>
  <p>The <span class="computeroutput">http_flush()</span> (with 1 as a value for it&quot;s optional
  argument) is used to request turning on the chunked encoding. If the client&quot;s
  user agent supports the encoding, then the data accumulated so far in the
  server&quot;s output buffer are sent to the client as the first chunk, the
  request is put in special &quot;chunked mode&quot; and the <span class="computeroutput">http_flush()</span>
  returns a non-zero integer. When in that mode a new chunk is sent
  to the client either when the internal 4k buffer is filled up or when the client
  calls <span class="computeroutput">http_flush()</span> again to flush the buffer and send it as a chunk.
	  The client disconnection is handled as <a href="webappdevelopment.html#fp_httphandleclidisconnect">usual</a>.</p>
<br />

<a name="mksimpledynapages" />
    <h3>12.3.9. Making Simple Dynamic Web Pages</h3>
  <p>
The directory where the pages reside must be marked as executable.
Use the <a href="fn_vhost_define.html">vhost_define</a> function or
the <a href="htmlconductorbar.html#httpvirtualdirs">Administration Interface</a> to do this:
</p>
<div>
      <pre class="programlisting">
vhost_define (lpath=&gt;&#39;/example_location&#39;, ppath=&gt;&#39;/example_location/&#39;, vsp_user=&gt;&#39;demo&#39;);
</pre>
    </div>

  <p>
The usual way to make an Dynamic page is to make a HTML skeleton and insert
Virtuoso/PL code in appropriate places to fill in the rest dynamically.  Consider
the following example as a demonstration of such technique.  Note that the
example is made in four steps but in practice this can be one.
</p>
  <p>
Suppose we have a table Demo.demo.Shippers (from the Demo database of the
standard distribution).  We can make a simple page for editing it.
</p>

<ol>
      <li>
    <div class="formalpara">
          <strong>Building The HTML Skeleton</strong>
      <p>
We define one form for editing and adding entries and a table for listing the existing shippers.
    </p>
    <div>
            <pre class="programlisting">
&lt;HTML&gt;
  &lt;BODY&gt;

    &lt;!-- edit form --&gt;
    &lt;FORM name=&quot;ShippersForm&quot; method=&quot;POST&quot; action=&quot;shippers.vsp&quot;&gt;
       &lt;INPUT type=&quot;hidden&quot; name=&quot;ShipperID&quot; value=&quot;&quot;&gt;
       &lt;TABLE&gt;
         &lt;TR&gt;
	   &lt;TD&gt;Company Name&lt;/TD&gt;
	   &lt;TD&gt;&lt;input type=&quot;text&quot; name=&quot;CompanyName&quot; value=&quot;&quot;&gt;&lt;!-- CompanyName --&gt;&lt;/TD&gt;
	 &lt;/TR&gt;
         &lt;TR&gt;
	   &lt;TD&gt;Phone&lt;/TD&gt;
    	   &lt;TD&gt;&lt;INPUT type=&quot;text&quot; name=&quot;Phone&quot; value=&quot;&quot;&gt;&lt;!-- Phone number --&gt;&lt;/TD&gt;
	 &lt;/TR&gt;
         &lt;TR&gt;&lt;TD colspan=&quot;2&quot;&gt;&lt;input type=&quot;submit&quot; name=&quot;accept&quot; value=&quot;Accept&quot;&gt;&lt;/TD&gt;&lt;/TR&gt;
       &lt;/TABLE&gt;
    &lt;/FORM&gt;
    &lt;!-- end of form --&gt;

    &lt;!-- list of entries --&gt;
    &lt;TABLE&gt;
       &lt;TR&gt;&lt;TD&gt;Company Name&lt;/TD&gt;&lt;TD&gt;Phone #&lt;/TD&gt;&lt;TD colspan=&quot;2&quot;&gt;Action&lt;/TD&gt;&lt;/TR&gt;
       &lt;!--TR&gt;&lt;TD&gt;CompanyName&lt;/TD&gt;&lt;TD&gt;Phone&lt;/TD&gt;&lt;TD&gt;Edit URI&lt;/TD&gt;&lt;TD&gt;Delete URI&lt;/TD&gt;&lt;/TR--&gt;
    &lt;/TABLE&gt;
    &lt;!-- end of list --&gt;
  &lt;/BODY&gt;
&lt;/HTML&gt;
    </pre>
          </div>
  </div>
</li>
      <li>
  <div class="formalpara">
          <strong>Filling a List of Entries</strong>
    <p>
We have added in part &#39;list of entries&#39; one active part (for select ...).
And using &lt;?=...?&gt; shortcut we have made for each row in database table
one row in table defined in step 1.  Also we have added two useful links
&#39;Edit&#39; and &#39;Delete&#39; with URL parameter &#39;EDIT&#39; and &#39;DELETE&#39; whose value
is equal to the primary key value of the row;
    </p>
    <div>
            <pre class="programlisting">
&lt;HTML&gt;
  &lt;BODY&gt;

    &lt;!-- edit form --&gt;
    &lt;FORM name=&quot;ShippersForm&quot; method=&quot;POST&quot; action=&quot;shippers.vsp&quot;&gt;
       &lt;INPUT type=&quot;hidden&quot; name=&quot;ShipperID&quot; value=&quot;&quot;&gt;
       &lt;TABLE&gt;
         &lt;TR&gt;
	   &lt;TD&gt;Company Name&lt;/TD&gt;
	   &lt;TD&gt;&lt;input type=&quot;text&quot; name=&quot;CompanyName&quot; value=&quot;&quot;&gt;&lt;!-- CompanyName --&gt;&lt;/TD&gt;
	 &lt;/TR&gt;
         &lt;TR&gt;
	   &lt;TD&gt;Phone&lt;/TD&gt;
    	   &lt;TD&gt;&lt;INPUT type=&quot;text&quot; name=&quot;Phone&quot; value=&quot;&quot;&gt;&lt;!-- Phone number --&gt;&lt;/TD&gt;
	 &lt;/TR&gt;
         &lt;TR&gt;&lt;TD colspan=&quot;2&quot;&gt;&lt;input type=&quot;submit&quot; name=&quot;accept&quot; value=&quot;Accept&quot;&gt;&lt;/TD&gt;&lt;/TR&gt;
       &lt;/TABLE&gt;
    &lt;/FORM&gt;
    &lt;!-- end of form --&gt;

    &lt;!-- list of entries --&gt;
    &lt;TABLE&gt;
       &lt;TR&gt;&lt;TD&gt;Company Name&lt;/TD&gt;&lt;TD&gt;Phone #&lt;/TD&gt;&lt;TD colspan=&quot;2&quot;&gt;Action&lt;/TD&gt;&lt;/TR&gt;
       &lt;!--TR&gt;&lt;TD&gt;CompanyName&lt;/TD&gt;&lt;TD&gt;Phone&lt;/TD&gt;&lt;TD&gt;Edit URI&lt;/TD&gt;&lt;TD&gt;Delete URI&lt;/TD&gt;&lt;/TR--&gt;
       &lt;?vsp
         for select ShipperID, CompanyName, Phone from Demo.demo.Shippers do
          {
       ?&gt;
       &lt;TR&gt;
         &lt;TD&gt;&lt;?=CompanyName?&gt;&lt;/TD&gt;
	 &lt;TD&gt;&lt;?=Phone?&gt;&lt;/TD&gt;
	 &lt;TD&gt;&lt;a href=&quot;shippers.vsp?EDIT=&lt;?=ShipperID?&gt;&quot;&gt;Edit&lt;/a&gt;&lt;/TD&gt;
	 &lt;TD&gt;&lt;a href=&quot;shippers.vsp?DELETE=&lt;?=ShipperID?&gt;&quot;&gt;Delete&lt;/a&gt;&lt;/TD&gt;
       &lt;/TR&gt;
       &lt;?vsp
          }
       ?&gt;
    &lt;/TABLE&gt;
    &lt;!-- end of list --&gt;
  &lt;/BODY&gt;
&lt;/HTML&gt;
    </pre>
          </div>
  </div>
</li>
      <li>
  <div class="formalpara">
          <strong>Retrieving Parameters and Filling in The Form</strong>
    <p>We must retrieve the parameters &#39;Delete&#39; and &#39;Edit&#39; from the URL and fill in
the form elements
</p>
    <p>
We have added a section to the top of the page that we use to recognize what operation to perform
and do the appropriate action in the database.  In the case of editing we use the values
input on the form.
    </p>

    <div>
            <pre class="programlisting">
&lt;?vsp
declare company_name, phone_number varchar;
declare shipper_id, operation integer;
declare shipper_info
  cursor for select CompanyName, Phone
    from Demo.demo.Shippers where ShipperID = shipper_id;

company_name := &#39;&#39;;
phone_number := &#39;&#39;;
operation := 0;

shipper_id := atoi (get_keyword (&#39;EDIT&#39;, params, &#39;0&#39;));

if (shipper_id &gt; 0)
  {
    whenever not found goto not_found_any;
    open shipper_info (prefetch 1);
    fetch shipper_info into company_name, phone_number;
not_found_any:
    close shipper_info;
    goto display_page;
  }

shipper_id := atoi (get_keyword (&#39;DELETE&#39;, params, &#39;0&#39;));

if (shipper_id &gt; 0)
  {
    delete from Demo.demo.Shippers where ShipperID = shipper_id;
    goto display_page;
  }

display_page:

?&gt;

&lt;HTML&gt;
  &lt;BODY&gt;

    &lt;!-- edit form --&gt;
    &lt;FORM name=&quot;ShippersForm&quot; method=&quot;POST&quot; action=&quot;shippers.vsp&quot;&gt;
       &lt;INPUT type=&quot;hidden&quot; name=&quot;ShipperID&quot; value=&quot;&lt;?=shipper_id?&gt;&quot;&gt;
       &lt;TABLE&gt;
         &lt;TR&gt;
	   &lt;TD&gt;Company Name&lt;/TD&gt;
	   &lt;TD&gt;&lt;input type=&quot;text&quot; name=&quot;CompanyName&quot; value=&quot;&lt;?=company_name?&gt;&quot;&lt;/TD&gt;
	 &lt;/TR&gt;
         &lt;TR&gt;
	   &lt;TD&gt;Phone&lt;/TD&gt;
    	   &lt;TD&gt;&lt;INPUT type=&quot;text&quot; name=&quot;Phone&quot; value=&quot;&lt;?=phone_number?&gt;&quot;&lt;/TD&gt;
	 &lt;/TR&gt;
         &lt;TR&gt;&lt;TD colspan=&quot;2&quot;&gt;&lt;input type=&quot;submit&quot; name=&quot;accept&quot; value=&quot;Accept&quot;&gt;&lt;/TD&gt;&lt;/TR&gt;
       &lt;/TABLE&gt;
    &lt;/FORM&gt;
    &lt;!-- end of form --&gt;


    &lt;!-- list of entries --&gt;
    &lt;TABLE&gt;
       &lt;TR&gt;&lt;TD&gt;Company Name&lt;/TD&gt;&lt;TD&gt;Phone #&lt;/TD&gt;&lt;TD colspan=&quot;2&quot;&gt;Action&lt;/TD&gt;&lt;/TR&gt;
       &lt;!--TR&gt;&lt;TD&gt;CompanyName&lt;/TD&gt;&lt;TD&gt;Phone&lt;/TD&gt;&lt;TD&gt;Edit URI&lt;/TD&gt;&lt;TD&gt;Delete URI&lt;/TD&gt;&lt;/TR--&gt;
       &lt;?vsp
         for select ShipperID, CompanyName, Phone from Demo.demo.Shippers do
          {
       ?&gt;
       &lt;TR&gt;
         &lt;TD&gt;&lt;?=CompanyName?&gt;&lt;/TD&gt;
	 &lt;TD&gt;&lt;?=Phone?&gt;&lt;/TD&gt;
	 &lt;TD&gt;&lt;a href=&quot;shippers.vsp?EDIT=&lt;?=ShipperID?&gt;&quot;&gt;Edit&lt;/a&gt;&lt;/TD&gt;
	 &lt;TD&gt;&lt;a href=&quot;shippers.vsp?DELETE=&lt;?=ShipperID?&gt;&quot;&gt;Delete&lt;/a&gt;&lt;/TD&gt;
       &lt;/TR&gt;
       &lt;?vsp
          }
       ?&gt;
    &lt;/TABLE&gt;
    &lt;!-- end of list --&gt;
  &lt;/BODY&gt;
&lt;/HTML&gt;
    </pre>
          </div>
  </div>
</li>
      <li>
  <div class="formalpara">
          <strong>Editing Form Logic</strong>
    <p>
We have a logic in the same initialization part of the page that retrieves
a &#39;ShipperID&#39; parameter, so if this parameter exists in the params array then
the operation is to perform an insert, otherwise we must update a record.
    </p>

    <div>
            <pre class="programlisting">
&lt;?vsp
declare company_name, phone_number varchar;
declare shipper_id integer;
declare shipper_info
  cursor for select CompanyName, Phone
    from Demo.demo.Shippers where ShipperID = shipper_id;

company_name := &#39;&#39;;
phone_number := &#39;&#39;;

shipper_id := atoi (get_keyword (&#39;EDIT&#39;, params, &#39;0&#39;));
-- If the current operation is edit then we retrieve the Company Name and Phone
if (shipper_id &gt; 0)
  {
    whenever not found goto not_found_any;
    open shipper_info (prefetch 1);
    fetch shipper_info into company_name, phone_number;
not_found_any:
    close shipper_info;
    goto display_page;
  }

shipper_id := atoi (get_keyword (&#39;DELETE&#39;, params, &#39;0&#39;));

-- If the operation is delete then delete it (if any error
-- occurred then HTTP server will handle it)
if (shipper_id &gt; 0)
  {
    delete from Demo.demo.Shippers where ShipperID = shipper_id;
    shipper_id := 0; -- reset it to prevent submission of wrong shipper id
    goto display_page;
  }

-- If pressed button Accept then we can recognize the operation
if (&#39;&#39; &lt;&gt; get_keyword (&#39;accept&#39;, params, &#39;&#39;))
  {
    shipper_id := atoi (get_keyword (&#39;ShipperID&#39;, params, &#39;0&#39;));
    company_name := get_keyword (&#39;CompanyName&#39;, params, &#39;unknown&#39;);
    phone_number := get_keyword (&#39;Phone&#39;, params, &#39;N/A&#39;);
    -- the old entry going edited
    if (shipper_id &gt; 0)
        update Demo.demo.Shippers set CompanyName = company_name, Phone = phone_number
	    where ShipperID = shipper_id;
    else -- this is an new entry
      {
        shipper_id := coalesce ((select max(ShipperID) from Demo.demo.Shippers), 0) + 1;
        insert into Demo.demo.Shippers (ShipperID,CompanyName,Phone)
	    values (shipper_id,company_name,phone_number);
      }
    company_name := &#39;&#39;; -- we clear all entered data
    phone_number := &#39;&#39;;
    shipper_id := 0; -- to prevent setting of wrong shipper id in form
  }

display_page:

?&gt;

&lt;HTML&gt;
  &lt;BODY&gt;
    &lt;H3&gt;Editing a shipment companies&lt;/H3&gt;
    &lt;!-- edit form --&gt;
    &lt;FORM name=&quot;ShippersForm&quot; method=&quot;POST&quot; action=&quot;shippers.vsp&quot;&gt;
       &lt;INPUT type=&quot;hidden&quot; name=&quot;ShipperID&quot; value=&quot;&lt;?=shipper_id?&gt;&quot;&gt;
       &lt;TABLE&gt;
         &lt;TR&gt;
	   &lt;TD&gt;Company Name&lt;/TD&gt;
	   &lt;TD&gt;&lt;input type=&quot;text&quot; name=&quot;CompanyName&quot; value=&quot;&lt;?=company_name?&gt;&quot;&lt;/TD&gt;
	 &lt;/TR&gt;
         &lt;TR&gt;
	   &lt;TD&gt;Phone&lt;/TD&gt;
    	   &lt;TD&gt;&lt;INPUT type=&quot;text&quot; name=&quot;Phone&quot; value=&quot;&lt;?=phone_number?&gt;&quot;&lt;/TD&gt;
	 &lt;/TR&gt;
         &lt;TR&gt;&lt;TD colspan=&quot;2&quot;&gt;&lt;input type=&quot;submit&quot; name=&quot;accept&quot; value=&quot;Accept&quot;&gt;&lt;/TD&gt;&lt;/TR&gt;
       &lt;/TABLE&gt;
    &lt;/FORM&gt;
    &lt;!-- end of form --&gt;


    &lt;!-- list of entries --&gt;
    &lt;TABLE&gt;
       &lt;TR&gt;&lt;TD&gt;Company Name&lt;/TD&gt;&lt;TD&gt;Phone #&lt;/TD&gt;&lt;TD colspan=&quot;2&quot;&gt;Action&lt;/TD&gt;&lt;/TR&gt;
       &lt;!--TR&gt;&lt;TD&gt;CompanyName&lt;/TD&gt;&lt;TD&gt;Phone&lt;/TD&gt;&lt;TD&gt;Edit URI&lt;/TD&gt;&lt;TD&gt;Delete URI&lt;/TD&gt;&lt;/TR--&gt;
       &lt;?vsp
         for select ShipperID, CompanyName, Phone from Demo.demo.Shippers do
          {
       ?&gt;
       &lt;TR&gt;
         &lt;TD&gt;&lt;?=CompanyName?&gt;&lt;/TD&gt;
	 &lt;TD&gt;&lt;?=Phone?&gt;&lt;/TD&gt;
	 &lt;TD&gt;&lt;a href=&quot;shippers.vsp?EDIT=&lt;?=ShipperID?&gt;&quot;&gt;Edit&lt;/a&gt;&lt;/TD&gt;
	 &lt;TD&gt;&lt;a href=&quot;shippers.vsp?DELETE=&lt;?=ShipperID?&gt;&quot;&gt;Delete&lt;/a&gt;&lt;/TD&gt;
       &lt;/TR&gt;
       &lt;?vsp
          }
       ?&gt;
    &lt;/TABLE&gt;
    &lt;!-- end of list --&gt;
  &lt;/BODY&gt;
&lt;/HTML&gt;
    </pre>
          </div>
  </div>
</li>
      <li>
  <div class="formalpara">
          <strong>Final Remarks</strong>
    <p>
The page for shippers does not have any specific error-handling.  If there are any
SQL errors produced the HTTP server will display the error number and the server
error message. For example, if we trying to delete an record of a predefined
shippers we would have a foreign key violation to which the server would respond:
    </p>
    <div>
            <pre class="screen">
&#39;SQL Error S1000 DELETE statement conflicted with
  COLUMN REFERENCE constraint &quot;Orders_Shippers_ShipVia_ShipperID&quot;&#39;
    </pre>
          </div>
    <p>
We can, however, add PL code to handle errors and display a different page.
    </p>
  </div>
</li>
    </ol>
<br />

<a name="xmlthtmloutmd" />
    <h3>12.3.10. Generation of non-HTML output</h3>
    <p>
	VSP pages are not restricted to generating  only HTML markup.
	In order  to generate non-HTML markup the VSP page MUST conform to the target  format specification,
	for example if XML output is needed, the markup MUST follow XML syntax rules.  The output sent to the user agent is entirely controlled by the scripting on the page, no constant headers beyond the required HTTP ones are added by the serber.
    </p>
    <p>
	Also it is important when output is not HTML that the HTTP header field
	&#39;Content-Type&#39;  be set to appropriate MIME type (for example &#39;text/xml&#39;, &#39;text/plain&#39; etc)
	using <span class="computeroutput">http_header()</span>.
    </p>
    <a name="" />
    <div class="example">
      <div class="exampletitle">XML generation</div>
	<p>The following example shows how an XML document can be generated using a VSP page</p>
	<div>
        <pre class="programlisting">
	    &lt;?vsp
	        -- source of the xmldemo.vsp
	        declare txt varchar;
		http_header (&#39;Content-Type: text/xml\r\n&#39;);
		txt := &#39;this is a XML test&#39;;
   	    ?&gt;&lt;?xml version=&quot;1.0&quot; ?&gt;
	    &lt;document&gt;
		&lt;para&gt;&lt;?= txt ?&gt;&lt;/para&gt;
	    &lt;/document&gt;
	    </pre>
      </div>
    </div>
    <a name="" />
    <div class="example">
      <div class="exampletitle">WML generation</div>
	<p>The following example shows how a WML page can be generated using a VSP page</p>
	<div>
        <pre class="programlisting">
	    &lt;?vsp
	    	-- source of the wmldemo.vsp
	        declare txt varchar;
	    	http_header (&#39;Content-type: text/vnd.wap.wml\r\n&#39;);
		txt := &#39;this is a WML test&#39;;
	    ?&gt;&lt;?xml version=&quot;1.0&quot; ?&gt;
	    &lt;!DOCTYPE wml PUBLIC &quot;-//WAPFORUM//DTD WML 1.1//EN&quot; &quot;http://www.wapforum.org/DTD/wml_1.1.xml&quot;&gt;
	    &lt;wml&gt;
		&lt;card&gt;
		    &lt;p&gt;&lt;?= txt ?&gt;&lt;/p&gt;
		&lt;/card&gt;
	    &lt;/wml&gt;
	    </pre>
      </div>
    </div>
    <div class="tip">
      <div class="tiptitle">See Also:</div>
	<p>
        <a href="/tutorial/wap/index.vsp">WML Tutorials</a>
      </p>
    </div>

<br />


  <a name="xmlthtmloutmd" />
    <h3>12.3.11. Post VSP XSLT Transformation Mode</h3>

  <p>
The Virtuoso server can perform server-side XSLT transformations on the
internal stream data.  Suppose we have an XML document, we can tell the
HTTP server to invoke XSLT processor before sending the reply to the user agent.
We do this by making a call to the <a href="fn_http_xslt.html">http_xslt()</a> function
inside VSP or any procedure called from it and pass the URL of the stylesheet
and probably some parameters.</p>

<p>
      <a href="fn_http_xslt.html">
  http_xslt(in <span class="parameter">style_sheet_URI</span>,  varchar [, in <span class="parameter">parameters</span> any])</a>
    </p>

  <p>The VSP page will produce an XML document,
  rather than HTML. The XSL stylesheet will then produce the required
  output for the user-agent, which could be more XML or HTML.</p>

  <p>The XSL stylesheet could also be generated using VSP.</p>

<a name="" />
    <div class="example">
      <div class="exampletitle">In Server Transformation of XML</div>
<div>
        <pre class="programlisting">
&lt;?vsp
declare ses any;
ses := string_output ();
xml_auto (&#39;select ShipperID, CompanyName, Phone from Demo.demo.Shippers
  for xml auto element&#39;, &#39;&#39;, ses);

http (&#39;&lt;list&gt;&#39;);
http (string_output_string (ses));
http (&#39;&lt;/list&gt;&#39;);
http_xslt (&#39;file:/samples/xslt/shippers.xsl&#39;);
?&gt;
</pre>
      </div>

<p>Where shippers.xsl will have the following content:</p>
<div>
        <pre class="programlisting">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;
&lt;xsl:output method=&quot;html&quot;/&gt;
&lt;xsl:template match=&quot;/&quot;&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Shippers list&lt;/title&gt;
&lt;/head&gt;
&lt;body link=&quot;#0000b4&quot; vlink=&quot;#0000b4&quot; bgcolor=&quot;#ffffff&quot;&gt;
&lt;xsl:apply-templates/&gt;
&lt;/body&gt;
&lt;/html&gt;
&lt;/xsl:template&gt;
&lt;xsl:template match=&quot;list&quot;&gt;
&lt;table&gt;
&lt;tr&gt;&lt;td&gt;ID&lt;/td&gt;&lt;td&gt;Name&lt;/td&gt;&lt;td&gt;Phone&lt;/td&gt;&lt;/tr&gt;
&lt;xsl:apply-templates/&gt;
&lt;/table&gt;
&lt;/xsl:template&gt;
&lt;xsl:template match=&quot;Shippers&quot;&gt;
&lt;tr&gt;
&lt;td&gt;&lt;xsl:value-of select=&quot;ShipperID&quot;/&gt;&lt;/td&gt;
&lt;td&gt;&lt;xsl:value-of select=&quot;CompanyName&quot;/&gt;&lt;/td&gt;
&lt;td&gt;&lt;xsl:value-of select=&quot;Phone&quot;/&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre>
      </div>
</div>
<br />

<a name="xmlforproducingvsp" />
    <h3>12.3.12. XML &amp; XSLT Generated VSP Pages</h3>
  <p>
The Virtuoso HTTP server provides a special case for producing VSP pages.
For this purpose the extensions .vxml and .vxsl are reserved.  If the
requested document is named dummy.vxml then the HTTP server will try to locate
dummy.vxsl.  If the dummy.vxsl exists then it will perform an XSLT transformation
using .vxml as a target XML document and .vxsl as a XSLT stylesheet.  After
successful transformation it will compile a result from it in the usual way
and then perform execute.</p>
<p>The requirements are: XML document with extension .vxml,
XSLT sheet with the same name, location but extension .vxsl.  The
location of these files must be set to allow execution
(see <a href="webserver.html#virtdir">Virtual Directories Support and Execution Privileges</a>).
</p>
<a name="ex_vxsl1" />
    <div class="example">
      <div class="exampletitle">Executable (V)XSL</div>
<p>
Source of portfolio.vxml
</p>
<div>
        <pre class="programlisting">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;portfolio.xsl&quot;?&gt;
&lt;portfolio xmlns:dt=&quot;urn:schemas-microsoft-com:datatypes&quot; xml:space=&quot;preserve&quot;&gt;
&lt;stock exchange=&quot;nyse&quot;&gt;
&lt;name&gt;zacx corp&lt;/name&gt;
&lt;symbol&gt;ZCXM&lt;/symbol&gt;
&lt;price dt:dt=&quot;number&quot;&gt;28.875&lt;/price&gt;
&lt;/stock&gt;
&lt;stock exchange=&quot;nasdaq&quot;&gt;
&lt;name&gt;zaffymat inc&lt;/name&gt;
&lt;symbol&gt;ZFFX&lt;/symbol&gt;
&lt;price dt:dt=&quot;number&quot;&gt;92.250&lt;/price&gt;
&lt;/stock&gt;
&lt;stock exchange=&quot;nasdaq&quot;&gt;
&lt;name&gt;zysmergy inc&lt;/name&gt;
&lt;symbol&gt;ZYSZ&lt;/symbol&gt;
&lt;price dt:dt=&quot;number&quot;&gt;20.313&lt;/price&gt;
&lt;/stock&gt;
&lt;/portfolio&gt;
</pre>
      </div>

<p>
Source of portfolio.vxsl
</p>
<div>
        <pre class="programlisting">
&lt;?xml version=&#39;1.0&#39;?&gt;
&lt;xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/TR/WD-xsl&quot;&gt;
&lt;xsl:template match=&quot;/&quot;&gt;
&lt;HTML&gt;
&lt;BODY&gt;
&lt;TABLE BORDER=&quot;2&quot;&gt;
&lt;TR&gt;
&lt;TD&gt;Symbol&lt;/TD&gt;
&lt;TD&gt;Name&lt;/TD&gt;
&lt;TD&gt;Price&lt;/TD&gt;
&lt;/TR&gt;
&lt;xsl:for-each select=&quot;portfolio/stock&quot;&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;xsl:value-of select=&quot;symbol&quot;/&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;xsl:value-of select=&quot;name&quot;/&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;xsl:value-of select=&quot;price&quot;/&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;/xsl:for-each&gt;
&lt;/TABLE&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;
&lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre>
      </div>

<p>
The result of retrieving portfolio.vxml
</p>
<div>
        <pre class="programlisting">
&lt;HTML&gt;
&lt;BODY&gt;
&lt;TABLE BORDER=&quot;2&quot;&gt;
&lt;TR&gt;&lt;TD&gt;Symbol&lt;/TD&gt;&lt;TD&gt;Name&lt;/TD&gt;&lt;TD&gt;Price&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;ZCXM&lt;/TD&gt;&lt;TD&gt;zacx corp&lt;/TD&gt;&lt;TD&gt;28.875&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;ZFFX&lt;/TD&gt;&lt;TD&gt;zaffymat inc&lt;/TD&gt;&lt;TD&gt;92.250&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;ZYSZ&lt;/TD&gt;&lt;TD&gt;zysmergy inc&lt;/TD&gt;&lt;TD&gt;20.313&lt;/TD&gt;&lt;/TR&gt;
&lt;/TABLE&gt;
&lt;/BODY&gt;
&lt;/HTML&gt;
</pre>
      </div>
</div>

    		
	<br />

	

<table border="0" width="90%" id="navbarbottom">
    <tr>
        <td align="left" width="33%">
          <a href="wsacl.html" title="Web Services ACL (Access Control List)">Previous</a>
          <br />Web Services ACL (Access Control List)</td>
     <td align="center" width="34%">
          <a href="webappdevelopment.html">Chapter Contents</a>
     </td>
        <td align="right" width="33%">
          <a href="vspx.html" title="Virtuoso Server Pages for XML (VSPX)">Next</a>
          <br />Virtuoso Server Pages for XML (VSPX)</td>
    </tr>
    </table>
  </div>
  <div id="footer">
    <div>Copyright© 1999 - 2009 OpenLink Software All rights reserved.</div>
   <div id="validation">
    <a href="http://validator.w3.org/check/referer">
        <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" />
    </a>
    <a href="http://jigsaw.w3.org/css-validator/">
        <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" height="31" width="88" />
    </a>
   </div>
  </div>
 </body>
</html>