How Do Web Clients and Servers Communicate? JDBC

How do web clients(browsers such as Microsoft’s Internet Explorer and Mozilla’s Firefox) and servers (servlet containers—such as Apache Tomcat—or application servers—such as IBM’s WebSphere) communicate? In the Java world, the web protocol HTTP (Hypertext Transfer Protocol), HTML (Hypertext Markup Language) forms, and Java servlets enable this communication. A web client sends an HTTP request, and the server receives the request, analyzes it, and sends back a proper HTTP response (dynamic content as another HTML message).

Java servlets are the central component of web applications and include servlet containers, request and response processing, sessions, redirection, and forward and include actions. Essentially, a servlet receives the request and then sends the response as another HTML message. We will focus on accessing databases using the JDBC API. Also, servlets may be used to authenticate users and control their access to server-side resources (such as data or metadata).

According to “Servlet Best Practices, Part 1”, since their introduction in 1996 servlets have dominated the server-side Java landscape and have become the standard way to interface Java to the Web. They are the foundation technology on which Java developers build web applications and, increasingly, web services. This chapter discusses best practices for servlet-based communication using JDBC development and deployment.

According to Sun, Java servlet technology provides web developers with a simple, consistent mechanism for extending the functionality of a web server and for accessing existing business systems. You can think of a servlet as an applet that runs on the server side—without a face or presentation. Java servlets have made many web applications possible. Servlets have access to the entire family of Java APIs, including the JDBC API to access enterprise databases.

As we will observe(by examining questions and answers in this chapter), JDBC provides a powerful, comprehensive interface for accessing databases from Java programs and servlets. The JDBC API allows any Java program—even an applet and servlet—to connect to a relational database management system(RDBMS) and perform queries and transactions. Servlets and JDBC are ideal for creating “dynamic contents.”

Using JDBC from a Java servlet involves a three-tier distributed application, consisting of a user interface(the web browser), business logic (a series of Java servlets), and database access. The user interface is an HTML file in a browser. The middle tier is a Java servlet that handles requests from the client web browser and provides access to the third tier, a database accessed via JDBC. Figure 8-1 presents a basic model (three-tier model) for accessing database metadata.

A basic model to access database metadata

A basic model to access database metadata

Our basic model (typically used by many web-based applications) for accessing database and database metadata has three tiers:

  • Tier 1: The web browser
  • Tier 2: The servlet/web server
  • Tier 3: The database server

Tier 1: The Web Browser

The first tier uses a web browser (such as Firefox or Internet Explorer), which is the default client for Internet applications. Client can use an HTML form for user input and the results of the database query (as dynamic content) are returned as an HTML/XML page.

Tier 2: The Servlet Container

The second tier is implemented with a servlet container (such as Tomcat, BEA’s WebLogic Server, or WebSphere) running Java servlets or JavaServer Pages(JSP). The Java servlet is able to receive the user’s request(the web browser sends an HTTP request) and access the database (using the JDBC API) and database metadata(using the JDBC API) and return the result as an HTML/XML page.

Tier 3: The Database Server

The third tier is the back-end database server. The Java servlet can access information in the database provided that a JDBC driver is available. JDBC drivers are available for most widely used databases (such as Oracle, MySQL, DB2, Sybase, etc.). A servlet can use one or many databases, either directly or indirectly.

Face Book Twitter Google Plus Instagram Youtube Linkedin Myspace Pinterest Soundcloud Wikipedia

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd Protection Status

JDBC Topics