Java Servlets

About Java Servlets

Java Servlets is a server side technology to build internet based comercial applications developed by Sun Microsystems. Servlets are platform independent java technology that run on set of standard interfaces and JVM (Java Virtual Machine). Servlets are built, written in java. Regardless of Servlets written in java, their clients may have written in any languages. Java Servlets provide an object-oriented and extensible middle tier for web server based, distributed java applications. Java Servlets is a technology that can access all of the java APIs such as JDBC, JNDI, RMI, EJB so on.
Web Server itself is not able to dynamically create web page content by pulling data from database. Web Server needs help of Java Servlets to get access to the data table, make accessible for users via internet to the client's browsers. Java Servlets is tied up with HTTP, and commonly referred to HTTP Servlet. Servlets is small portion of java code which is executed at the web Server in response to an HTTP request from a client's Browsers. Servlets can be used as a plug-in for instance a search engine or semi-customized applications such as web-based banking systems.

Java Servlet's work is mostly done behind the scene and not visible to the users. Servlets are run within a Web Server's namespace. Only the results of Servlet's processing such as data from database table which is converted to suit into the html form, are visible to the users via Graphical User Interface (GUI). Java Servlet's life-cycle (created & destroyed) is managed by Servlet Engine (Servlet Container). Servlet Container provies the runtime environment where servlets are executed. Java Servlet is supported by many popular web servers such as Appache, IIS, Netscape so on. Servlets run on server side whereas Applets run only on the Client side java enbled browser.

Java Servlets Work Flow

Servlets always run behind the scene on the Web Server. Servlets provide a framework to create applications that implement a HTML request/response. For intance, a Browser sends a request to the Webserver for HTML page content. The Webserver forward this request to Servlet via its extender software. Servlet processes the request by pulling data from data table, converting them in HTML format, and sending back to the Web Server. Then, Web Server forward the result back to Web Browser who initiated the request for HTML page content, hence displaying result on the GUI.

How to create Servlets

Java Servlets are created just like other java source file on the ASCII Editor. Compiled and run in a Java Virtual Machine.

<filename>.java (Source Code)
MyFirstServlet.java
<filename>.class (Compiled)
MyFirstServlet.class

import java.servlet.*;
public class MyFirstSerlet extends HttpServlet
    {
       public void service(ServletRequest request, ServletResponse response) 
      throws ServletException, IOException
      {
      ...
      }
      ...
   }
The service() method comes with two parameters: request and response. These parameters encapsulate data sent by the Browser client and provide access to parameters and allow Servlets to process result status, including errors.

How to run Servlets

Servlets are run using Web Servers such as Apache in the production environment. The Servlet Engine (Servlet Container) provides runtime environment to Servlets. Servlet Engine come as Standalone and Add-on. Some Web Server support Servlets right out of the box, meaning no need to install Third-party Add-on. This kind of Web Servers are called a Standalone Servlet Engine. Standalone Servlet Engine is a server that includes biult-in support for Servlets. Some example of Standalone Servlet Engines are Oracle Weblogic Application Server or Tomcat Server from Project Jakarta or WebSphere Application Server from IBM so on. On the other hand, Add-On Servlet Engine requires a third party Add-on installed such as Apache do not support Servlets right out of the box.

←Return To Menu

No comments:

OTN Discussion Forums: Message List - Database - General

Ask Tom HOT ARTICLES

 
© Copyright 2008 - 2011. All rights reserved to dba-sansar.blogspot.com.
All other blogs, posts and entries are the property of their respective authors.
Please email us for your comments and suggessions Click Here