Section 7.1.  XSLT processor as servlet

  
Prev don't be afraid of buying books Next

7.1 XSLT processor as servlet

7.1.1 Saxon servlet

A Java class written specifically to be run on a web server is called a servlet . A software layer that works as an interface between the actual web server (such as Apache) and Java servlets is called a servlet container or servlet engine . So the two things we need, besides a regular web server, are

  • an XSLT processor packaged as a servlet (as opposed to a regular runnable class file); and

  • a servlet engine to run this processor servlet.

Saxon includes a basic servlet class called SaxonServlet in the examples/java subdirectory of the Saxon distribution. This class is fairly simple and is included more as a proof-of-concept demo than a production-ready servlet implementation. For one thing, the only way to pass the names of the source document and the stylesheet to this servlet is via a URL of the form


 http://example.org/SaxonServlet?source=page.xml&style=style.xsl 


Can we simplify this? You may want to have the servlet fired for any .xml file requested from the server, as in


 http://example.org/page.xml 


The stylesheet URI in this case might be taken from the <?xml-stylesheet?> processing instruction in page.xml . This is possible if you

  • configure your server to associate all .xml files with the Saxon servlet; and

  • modify the Saxon servlet so that it can take the URI it is called with as source and use the processing instruction in the source document to find the stylesheet.

Better yet, install Cocoon ( 7.2 ) over Tomcat and let the former solve this problem in an elegant and generic fashion.

7.1.1.1 Tomcat servlet engine

A good servlet engine is Tomcat, [1] developed by the Apache Software Foundation. Tomcat is the reference implementation of the Java Servlet and JSP (Java Server Pages) technologies.

[1] jakarta.apache.org/tomcat

Tomcat may work as a servlet engine with another web server, such as Apache or Microsoft IIS, but it also contains a web server of its own. So, you don't have to run a full-featured web server if you want to install Tomcat on your local system to experiment with it. Note that you'll also need to install Tomcat (with or without a separate web server) if you want to run the Cocoon framework discussed in the next section.

Refer to 7.2.6 , steps 1 to 4, for instructions on installing and testing Tomcat. See the Tomcat documentation on how to install web applications (such as the Saxon servlet) into Tomcat.

 
  
Amazon


XSLT 2.0 Web Development
ASP.Net 2.0 Cookbook (Cookbooks (OReilly))
ISBN: 0596100647
EAN: 2147483647
Year: 2006
Pages: 90

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net