Building Java Servlets With Oracle JDeveloper
Building Java Servlets With Oracle JDeveloper
Chris Schalk
Oracle Corporation
Introduction
Developers today face a formidable task. They need to create large, distributed business applications. The actual
creation of any large application is problematic. This development process is compounded when an application is
distributed, or if that application resides in multiple pieces across a network. Especially when an Enterprise
application must be consistent and reliable across multiple platforms that are scattered across the Web.
A major issue concerns the deployment of such applications. On the one hand, the changes are being driven by
the rapid growth of business on the Internet, which has created new business models, reduced time to market, and
significantly changed the way corporations look at developing and deploying enterprise applications. On the
other hand, the Internet also provides the medium for accelerated adoption of distributed computing. It provides
standard protocols, like HTTP and IIOP, built on TCP/IP using the World Wide Web browser as its interface, and
it allows universal access to these applications. The Internet has created several new classes of applications, such
as electronic commerce and self-service applications that need to be integrated with traditional enterprise
applications.
An issue many enterprises face is the use of applications that are primarily standalone. These applications must
be created and launched as quickly as possible without being locked into one platform. The ideal enterprise
application would be one that was written once and which would run on all platforms.
Java is currently the most dynamic development environment in the industry. It allows you to build a set of tools
that can be used on any project with any client and on any platform. Prior to the introduction of Java technology,
the dream of code-reuse that was unveiled by the creation of object-oriented programming was not completely
fulfilled. If code cannot be reused on every platform, the benefits of code-reuse are limited. With Java
technology, you can assure a prospective client that a project is already halfway to completion, and that with this
headstart , they will have more time to formulate strategies that will assure them better market positioning. Now
there is an ideal solution for the deployment of such applications from the server side, that realizes the goal of
code reuse within a distributed environment. This solution is servlets
1. Enter the servlet’s package name, class name, and file path.
2. Specify the servlet’s thread model. Check the SingleThreadModel checkbox or leave it unchecked for the
multithreaded model.
A web server can concurrently execute a servlet’s service method in multiple threads. If a servlet’s service method
performs an action that is not thread-safe, you should select the SingleThreadModel. This model ensures that no
two threads will execute a servlet’s service methods concurrently. For example, if a service method updates a
servlet’s field, you should choose either the SingleThreadModel or implement the service method so that it is
thread-safe by synchronizing client update requests. For more information on writing thread-safe code, please see
JavaSoft’s Java Tutorial.
3. Select which methods the servlet will use. Check either the service method, which processes user requests and
responds back to the client, or one or more of the following:
• doGet, which handles GET, conditional GET and HEAD requests
• doPost, which handles POST requests
• doPut, which handles PUT requests
• doDelete, which handles DELETE requests
4. Click Next to proceed to the next wizard page, or Finish to create the servlet using the default values of the next
wizard page.
Enter the parameters to be passed to the servlet. The wizard will generate the code needed for the servlet to read
the parameter values at runtime. Click Add Parameter to open a new parameter entry line. Click Remove
Parameter to remove an existing parameter.
Now that the JDeveloper wizard has created the code for your servlet, you may customize it for your own needs
or you can run it as is. To run your servlet simply add your compiled class file into your webserver’s
environment. Using Sun’s Java WebServer this is a simple one step process which can be done via a browser.
Using the DBServlet Wizard, you can create a database servlet that generates a singlwe table or a master-detail HTML
form to query, browse, edit, insert, and view database information from two tables or views.
Paper 452 / Page 3
The process of creating a database servlet is as follows:
1. Define the servlet type and connect to a database.
2. Select database objects for the servlet.
3. Specify the join conditions for the servlet.
4. Select master (and detail) columns for the servlet.
5. Select a theme.
6. Finish the DBServlet Wizard.
The following topics describe this process in detail.
Specify the kind of servlet to create. This defines the the way the data is represented in the HTML form generated by
the servlet.
1. To create a master-detail servlet, click Master-Detail.
2. Click Next to proceed to the next wizard page.
1. Enter the class name, package name, and title of the servlet.
2. Enter the database connection information for the servlet. You can select an existing database connection or define
a new connection by clicking the Add... button. If you choose an existing connection, you can modify it as needed
by clicking the Edit... button. Clicking either the Add... or Edit... buttons, invokes the Connection Information
editor.
The database connection name you specify in this step is used by JDeveloper to name a special deployment XML
file for the servlet. For example, a servlet that uses database connection MyDbConnection will have a
corresponding XML file named MyDbConnection.xml.
1. Use the Connection Information editor if you are creating a new database connection, or modifying an existing
one. From the Driver page, choose a database driver for the servlet.
2. Click the Database tab to proceed to the next page.
3. From the Database page, choose a database driver for the servlet.
a. Enter the user name and password for the connection.
b. Click the security information prompt if you want the end user to login at runtime.
1. Select the database objects (tables, views, or both) you want to use in the servlet. Filter the available choices by
choosing either UserName Schema Objects or All Available Objects.
2. Click Next to proceed to the next wizard page.
1. Specify the join conditions to use for the master-detail relationship. You can select an existing join condition, or
click Add... to define a new condition. Click Remove... to remove a selected join condition from the list. Click to
Remove All... to remove all join conditions in the list.
2. Click Next to proceed to the next wizard page.
1. For the master database object in the servlet, select the columns you want to include.
2. Click Next to proceed to the next wizard page.
3. For the detail database object in the servlet, select the columns you want to include.
4. Click Next to proceed to the next wizard page.
Select a Theme
1. Select a theme for the look and feel of the HTML form generated dynamically by the servlet.
2. Click Next to proceed to the next wizard page.
Conclusion
By providing a set of easy to use wizards making the task of creating database interactive servlets incredibly easy,
JDeveloper provides the Java programmer with the most efficient development environment for creating scalable,
sophisticated servlet database applications.