background image

Duke's Bookstore Examples

<< The @Resource Annotation | Accessing Databases from Web Applications >>
<< The @Resource Annotation | Accessing Databases from Web Applications >>

Duke's Bookstore Examples

@Resources ({
@Resource (name=
"myDB" type=java.sql.DataSource),
@Resource(name=
"myMQ" type=javax.jms.ConnectionFactory)
})
The web application examples in this tutorial use the Java Persistence API to access relational
databases. This API does not require you to explicitly create a connection to a data source.
Therefore, the examples do not use the @Resource annotation to inject a data source. However,
this API supports the @PersistenceUnit and @PersistenceContext annotations for injecting
EntityManagerFactory
and EntityManager instances, respectively.
Chapter 25, "Persistence in
the Web Tier"
describes these annotations and the use of the Java Persistence API in web
applications.
Declaring a Reference to a Web Service
The @WebServiceRef annotation provides a reference to a web service. The following example
shows uses the @WebServiceRef annotation to declare a reference to a web service.
WebServiceRef
uses the wsdlLocation element to specify the URI of the deployed service's
WSDL file:
...
import javax.xml.ws.WebServiceRef;
...
public class ResponseServlet extends HTTPServlet {
@WebServiceRef(wsdlLocation=
"http://localhost:8080/helloservice/hello?wsdl")
static HelloService service;
Duke's Bookstore Examples
In Chapters
Chapter 4, "Java Servlet Technology"
through
Chapter 15, "Internationalizing and
Localizing Web Applications"
a common example, Duke's Bookstore, is used to illustrate the
elements of Java Servlet technology, JavaServer Pages technology, the JSP Standard Tag Library,
and JavaServer Faces technology. The example emulates a simple online shopping application.
It provides a book catalog from which users can select books and add them to a shopping cart.
Users can view and modify the shopping cart. When users are finished shopping, they can
purchase the books in the cart.
The Duke's Bookstore examples share common classes and a database schema. These files are
located in the directory tut-install/javaeetutorial5/examples/web/bookstore/. The
common classes are packaged into a JAR. Each of the Duke's Bookstore examples must include
this JAR file in their WAR files. The process that builds and packages each application also
builds and packages the common JAR file and includes it in the example WAR file.
The next section describes how to create the bookstore database tables and resources required
to run the examples.
Duke's Bookstore Examples
The Java EE 5 Tutorial · September 2007
96