SAXONICA

Saxon Documentation
Full Contents
About Saxon
Changes in this Release
Conditions of Use
Using XSLT 2.0
Using XQuery
| Introduction
| Running XQuery from the Command Line
| Invoking XQuery using the XQJ API
| Invoking XQuery from an application
| Calling XQuery Functions from Java
| Result Format
» | Compiling Queries to Java code
| Extensibility
| Extensions
| Use Cases
Handling Source Documents
XML Schema Processing
XPath API for Java
Saxon on .NET
Extensibility
Saxon Extensions
Sample Saxon Applications
The Saxon SQL Extension
XSLT Elements
XPath 2.0 Expression Syntax
Function Library
Standards Conformance

# Running a Compiled Query as a Servlet

If a query has been compiled as a servlet, the class file should be installed in the relevant application directory of the servlet container, and registered in the `web.xml` configuration file in the normal way.

The query can then be invoked using an HTTP GET request using the name assigned to the servlet in the configuration file

By default (see below) it is possible to specify query parameters in the URL used to invoke the query. For example if the URL is `http://localhost:8080/servet/qexample?x=10&y=20`, and if the query body declares external variables $x and $y, then these will be initialized to the values 10 and 20.

The query output will be serialized and written to the HTTP response stream. Serialization parameters can be written within the query using the `saxon:output` option declaration.

When you compile a query as a servlet, the Java class generated will extend `com.saxonica.deploy.CompiledQueryServlet`. Alternatively, you can nominate a superclass for the generated code, which should itself subclass `CompiledQueryServlet`, giving you more control over the behavior of the servlet, for example the way in which parameters are supplied. This is particularly useful if different servlets are to share resources such as access to in-memory documents.

During servlet initialization, the init() method attempts to determine whether the servlet context includes an attribute named `com.saxonica.servlet.applicationdata` that is an instance of the interface `SharedApplicationDataHandler`. If this object exists, it is called on each servlet request, at which point it has the opportunity to configure the `Controller` for the query execution, for example by supplying parameter values, setting a `URIResolver`, or otherwise.

If no `SharedApplicationDataHandler` object is available, external variables for the query can be specified as query parameters in the request URL. The names of query parameters are taken as local names of no-namespace variables, and the values are treated as UntypedAtomic strings (which will be converted to the declared type of the variable if necessary). Any query parameters that do not correspond to declared external variables in the query will be ignored.

Next