---

Linux Journal: Using Java Servlets with Database Connectivity

“The Common Gateway Interface (CGI) has and continues to be the
most commonly used method for creating dynamic and responsive web
pages. The main problem with CGI (that stems from the Hyper-Text
Transfer Protocol) is that each new client request results in a new
instance of the CGI executable being forked by the HTTP daemon.
This can lead to considerable resource consumption on web hosting
machinery. Many solutions exist to address this problem, most
focusing on keeping the executable persistent between client
requests. This has the added benefit of holding open costly
resources like database and socket connections.”

“Java is one of the newest kids on the block, but as a C and C++
coder I really like some of the features of this language. Its
object model is nice, it is (relatively) portable, and the class
libraries available from both Sun and third parties are extensive.
Servlets, a rather fanciful name, is the Java answer to the CGI
problem. Servlets are Java classes, loaded and kept resident by
the HTTP daemon. When the servlet is loaded, it is initialized by a
method call; at that point, database connections can be established
and held between client requests.
In addition to this, there
are a number of useful classes which facilitate the more complex
server/browser interactions such as cookies. Unfortunately, the
Servlet classes from Sun are still in a fluid state and, therefore,
code written now may be broken by future releases. This is a fact
of programming life and since this is a small application, not much
harm is likely.”

Complete
Story

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends, & analysis