Database Reference
In-Depth Information
Request parameters and attributes
If you browse the functions of the request extension module, you might notice that
both request parameters and attributes are mentioned:
• A request parameter is a name/value pair that was passed in from the client—for
instance, as part of the URL or as an input field of an HTML form. Parameter
values are always strings.
• A request attribute is a name/value pair that was set on the server. This was most
likely done by the URL controller (see “URL Mapping Using URL Rewriting” on
page 194 ), but if needed you can do it anywhere in your code using the
request:set-attribute function. Attribute values can be anything from simple
strings to complex XML fragments.
Request attributes are useful for internal communication between parts of your
application code when processing a request. They are also used by some internal
mechanisms as parameters to servlets (for an example of this, see “Advanced
URL Control” on page 203 ).
Uploading files
The request extension module can also be used for uploading files to the server. For
example, assume you want to upload a binary file to your server and store this in the
database. The page that offers this functionality must contain a form with encoding
type multipart/form-data , as in this HTML fragment:
<form enctype= "multipart/form-data" method= "post" action= "upload1-process.xq" >
<p> Upload binary file:
<input type= "file" size= "80" name= "FileUpload" />
<br/>
<input type= "submit" />
</p>
</form>
Access to the uploaded file is via the request:get-uploaded-file-data function.
You can store the result in the database by using the xmldb:store function, as in this
XQuery fragment:
let $ stored-file as xs:string ? := xmldb:store ( $ store-collection , $ store-resource ,
request:get-uploaded-file-data ( $ field-name ), 'application/octet-stream' )
This returns the path of the file as stored in the database. Other functions that might
be of interest here are request:get-uploaded-file-name for getting the original file
name and request:get-uploaded-file-size for getting the size of the file (and
optionally rejecting it if it is too large).
Search WWH ::




Custom Search