Saturday, February 14, 2015

The Structure and Deployment of Web Applications


A Web Application that may contain below contents.
(a) Static content
(b) JSP pages
(c) Servlet classes
(d) Deployment descriptor
(e) Tag libraries
(f) JAR files, and
(g) Java class files


A Web application exists as a structured hierarchy of directories.The root of this hierarchy serves as the document root for files that are part of the application.The root directory is usually known as the context path for example. When you access a web application www.test.com/MyWebApplication, 'MyWebApplication' is the document root which is also known as context path.


A special directory exists within the application hierarchy named "WEB-INF". This directory contains all things related to the application that aren't in the document root of the application.

The WEB-INF node is NOT part of the public document tree of the application hence no file contained in the WEB-INF directory may be served directly to a client by the container. However, the contents of the WEB-INF directory are visible to servlet code using the getResource and getResourceAsStream method calls on the ServletContext, and may be exposed using the RequestDispatcher calls

The contents of the WEB-INF directory are:

The /WEB-INF/web.xml deployment descriptor.

The /WEB-INF/classes/ directory for servlet and utility classes. The classes in this directory must be available to the application class loader.

The /WEB-INF/lib/*.jar area for Java ARchive files. These files contain servlets, beans, and other utility classes useful to the Web application. The Web application class loader must be able to load classes from any of these archive files.

What is a web application?


A web application is a dynamic view of an application in a web server or application server.
They are mainly two types
Presentation-oriented:
A presentation-oriented web application generates interactive web pages containing various types of markup language (HTML, XHTML, XML, and so on) and dynamic content in response to requests. This can be achieved by technologies such as JSF, Servlet, JSP, Spring etc.
Service-oriented:
A service-oriented web application implements the endpoint of a web service. These are often consumed by the above said application. This can be achieved mainly with the help of Webservice technologies. 

A web application consists of web components; static resource files, such as images and cascading style sheets (CSS), Code that generates dynamic content such as servlet and Java classes etc. 

The process for a java web application creation can be summarized as follows:

1.    Develop the web component code.
2.    Develop the web application deployment descriptor, if necessary.
3.    Compile the web application components and helper classes referenced by the components.
4.    Optionally, package the application into a deployable unit such as war
5.    Deploy the application into a web container.
6.    Access a URL that references the web application.

What is a servlet?

Servlets  are platform-independent Java classes which implements the Servlet interface or extends any abstract class which has this Servlet interface implementation defined in javax.servlet package. This has three essential methods for the life cycle of a servlet – init(), service(), and destroy(). They are implemented by every servlet (defined in SDK or self-defined) and are invoked at specific times by the server. Servlets interact with Web clients via a request/response paradigm implemented by the servlet container.

The hierarchy is as follows.

                       public interface Servlet

public abstract class GenericServlet  extends java.lang.Object
   implements Servlet, ServletConfig, java.io.Serializable

public abstract class HttpServlet extends GenericServlet
              implements java.io.Serializable

Tuesday, February 10, 2015

What is a Servlet Container?

Servlet container or Web container is a standalone component or the component of a web server that interacts with Java servlets. The container implements Java Servlet Specification whereas the servlet is a java class which conforms to Java Servlet Specification. Thus A web container is responsible for managing the lifecycle of servlets, mapping a URL to a particular servlet based on configuration and ensuring that the URL requester has the correct access rights.
All servlet containers must support HTTP as a protocol for requests and responses, but additional request/response-based protocols such as HTTPS (HTTP over SSL) may be supported.

In Servlet 2.4 Specification the sequence of events which will occur is given as,

1. A client (e.g., a Web browser) accesses a Web server and makes an HTTP re-
quest.
2. The request is received by the Web server and handed off to the servlet con-
tainer. The servlet container can be running in the same process as the host
Web server, in a different process on the same host, or on a different host from
the Web server for which it processes requests.
3. The servlet container determines which servlet to invoke based on the config-
uration of its servlets, and calls it with objects representing the request and re-
sponse.
4. The servlet uses the request object to find out who the remote user is, what
HTTP
POST
parameters may have been sent as part of this request, and other
relevant data. The servlet performs whatever logic it was programmed with,
and generates data to send back to the client. It sends this data back to the client
via the response object.
5. Once the servlet has finished processing the request, the servlet container en-
sures that the response is properly flushed, and returns control back to the host
Web server.

Tuesday, July 31, 2012

Introduction to Web Applications


Web applications are applications or software that is accessed over a network such as internet or an intranet. Web applications provide the user, some services or any type of content such as text, image, etc. These applications are usually accessed through web browsers such as InternetExplorer or Firefox etc.