Jetty has moved!
Jetty is a project at the Eclipse Foundation.
Homepage:http://www.eclipse.org/jetty
Downloads: http://download.eclipse.org/jetty/
Documentation:http://www.eclipse.org/jetty/documentation/current/
About:http://www.eclipse.org/jetty/about.php
Jetty Powered:http://www.eclipse.org/jetty/powered/
Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Next »

Servlet 2.5 Annotations and Resource Injections

The 2.5 Servlet Specification adds the ability to inject JNDI resources into fields and methods of servlets, filters and listeners, and also to perform certain callbacks at various points in the lifecycle of a web application.

JNDI resource injection and the lifecycle callbacks can be specified entirely within the web.xml file, or alternatively marked up as
annotations in your source code. You can even use a combination of annotations and web.xml declarations.

First, lets look at how to use web.xml for injections and callbacks.

Resource Injections and Callbacks specified in web.xml

Introduction

The Servlet 2.5 web.xml schema has been augmented to support the declaration of resource injection and lifecycle callbacks. We'll look at a couple of small examples of how to declare them in web.xml, but for more in-depth information, you should consult the Common Annotations for the Java Platform Specification (JSR250), the Servlet 2.5 Specification (JSR154) and the JavaEE Specification v5 (JSR244).

Here is a small example of the injection of a DataSource resource:

This example shows that the resource named java:comp/env/jdbc/mydatasource will be injected by Jetty into the the field named myDatasource or the method named setMyDatasource(javax.sql.DataSource) in the instance of the class com.acme.MyServlet before it goes into service.

Similarly, values for {{<env-entry>}}s can be injected:

This example shows the value 99.99 being injected into the field named maxAmount (or the method named setMaxAmount(Double)) in the instance of the class com.acme.MyServlet before it goes into service.

How to Configure in Jetty

To use injections and callbacks declared in web.xml, you do not need to do anything other than follow the instructions for setting up Jetty JNDI.

Resource Injections and Callbacks with Annotations

  • No labels
Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery