epubjs
Version:
Render ePub documents in the browser, across many devices
54 lines (53 loc) • 4.79 kB
HTML
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>Chapter 15. Web Applications and Web Services</title><link rel="stylesheet" href="core.css" type="text/css"/><meta name="generator" content="DocBook XSL Stylesheets V1.74.0"/></head><body><div class="chapter" title="Chapter 15. Web Applications and Web Services"><div class="titlepage"><div><div><h1 class="title"><a id="learnjava3-CHP-15"/>Chapter 15. Web Applications and Web
Services</h1></div></div></div><p>We’re now going to take a leap from the client side to the server side
to learn how to write web-based Java applications and services. What
distinguishes a web-based application from a regular Java program is that
much of the code, logic, or data resides on the server, at least initally,
and the user utilizes a web browser or a lightweight client to access it.
This is a very appealing model of software deployment facilitated by the
increased standardization and power of HTML and JavaScript in web browsers
as well as higher-speed Internet connectivity and better
application-to-application web service standards.</p><p>Most of this chapter is about the mechanics of the Servlet API, which
is a Java framework for writing application components for servers. The
Servlet API is used in both Java web applications and often in the
implementation of application-to-application web services. We’ll deal with
servlets directly in the first part of this chapter, when writing examples
used from a web browser. Later, we’ll look at application-level web services
that are designed to provide data and services to all types of client
applications in a more behind-the-scenes fashion. The two types of
server-side applications have some things in common, including how they can
be deployed to an application server using a Web Archive (WAR) file and the
fact that they are often combined in advanced applications that both render
pages on the server and use JavaScript to pull data from web services on the
client side.</p><p>The Servlet API lives in the <a id="I_indexterm15_id775903" class="indexterm"/><code class="literal">javax.servlet</code> package,
which is a standard Java API extension. Deploying and running servlets
requires an <span class="emphasis"><em>application server</em></span> or <span class="emphasis"><em>servlet
container</em></span>—a Java-based server that acts like a web server and
handles requests bound for servlet components—and so the Servlet API is not
bundled with the standard edition of Java. We will recommend that you
download Apache Tomcat to run the examples in this chapter and at that time,
you can grab the Servlet API JAR file from that distribution in order to
compile the example classes. Many Java IDEs can also install the necessary
JAR file for you automatically.</p><p>The APIs used for building and deploying application-to-application
web services are part of the <a id="I_indexterm15_id775932" class="indexterm"/><code class="literal">javax.jws</code> package. Although
the JWS API is also technically a standard extension, it is bundled with the
standard edition of Java and so you can write Java web service clients
out-of-the-box, with no additional components. You can even deploy web
services directly using a minimal built-in server functionality bundled with
the standard edition of Java with no additional application server required.
However, this feature is mostly useful for testing, as the built-in server
does not perform as well as the various other application servers such as
Tomcat. This chapter covers Java Servlet API 3.0 and JWS (JAX-WS) version
2.2.</p><p>Servers that support the full set of Java Enterprise APIs including
servlets, web services, JSPs, and older technology like Enterprise JavaBeans
are called <span class="emphasis"><em>application servers</em></span>. JBoss is a free, open
source <a class="ulink" href="http://www.jboss.org">Java application server</a>,
and BEA’s WebLogic is a popular commercial application server. The free
Apache Tomcat server that we’ll use in this chapter started out primarily as
a servlet container, but now runs web services and everything needed for
serious application development. Tomcat can be used by itself or in
conjunction with another web server such as Apache. Tomcat is easy to
configure and is a pure Java application, so you can use it on any platform
that has a Java VM. You can download it from <a class="ulink" href="http://jakarta.apache.org/tomcat/">http://jakarta.apache.org/tomcat/</a>.</p></div></body></html>