Showing posts with label server. Show all posts
Showing posts with label server. Show all posts

Monday, January 27, 2014

Web Application Artifacts in Servlet Technology

When we develop web applications in java servlet technology we need some of artifacts.

Before read this article please go through following article which will give more information about web application technologies in java


We need following artifacts. These are all very important to build servlet application in java
  1. Web application Directory Structure
  2. Deployment Configuration File
  3. Servlet Java Class
  4. Servlet-api.jar file
  5. Servlet Container Provider Servers (Tomcat)

Web application Directory Structure

In any web application java that should have some particular directory structure. Once we done all development we need package as .war file.

What is war (Web Archive)?

A Web Archive is web application standard package that represent the web application. A war can be understood by any web container/server. We need to package ad war and deploy into servers.

We have java commands to package web application as war file. We can also make war file from eclipse IDE tool.

The following is example web application directory structure.




The following is more about web application directory structure


Deployment Configuration File

Deployment configuration provides the full information about application and its resources. This information we will provide through the web.xml file and it have many predefined tags all tags information provided in DTD file.

Coming to servlet web application on web.xml we need to configure the servlet. Container will use this information and execute the appropriate servlet when client is requested for dynamic response through simple http URL notation.

The following is full details of tags in web.xml


The following is simple servlet information in web.xml file

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
 <servlet>
    <servlet-name> helloWorldServlet </servlet-name>
    <servlet-class>com.liferaysavvy.meera.HelloWorldServlet</servlet-class>
 </servlet>
 <servlet-mapping>
    <servlet-name>helloWorldServlet </servlet-name>
    <url-pattern>/helloworldservlet </url-pattern>
 </servlet-mapping>
</web-app>

Servlet

Servlet is parent tag here servlet definition will start. This tag has two child tags servlet name and servlet class.

Servlet name:

 Servlet name is simple human understandable name which is reference name to servlet class.

Servlet class:

Servlet class is simple java class and it contains the servlet behavior

Servlet mapping

Servlet mapping is simple URL information to servlet container which helps to the container when client request for dynamic request. From the URL it will identify which servlet to be invoke/execute

Servlet mapping tag will map the servlet with some url pattern. This tag has two child tags i.e. Servlet Name and url-pattern

Servlet name we already know

url-pattern

url pattern tag will map the servlet with simple http url pattern. This url pattern will be used by client to invoke servlet.

Note:

When we map servlet class with URL pattern we need to use servlet name as common tag.

Servlet Java Class

Servlet java class is simple java class which should implements the java servlet interface. Servlet interface is simple java interface have certain abstract methods. To get servlet behavior to java class we need to implement servlet interface.

Servlet API implementation provides some servlet implementation classes. We will use those classes and interfaces to get servlet behavior to our class.

Generally we need to implement servlet interface to our java class but in the implementation we will use another java class that already implemented servlet interface.

The following is servlet implementation hierarchy



Note:

We will use Http Servlet and it will use http protocol to invoke the servlet from client. We can also implement servlet for other protocols and as of now we will have http protocol based servlet implementation is available.

Servlet API implementation packaged as servlet-api.jar file which is from sun micro system implementation.

Servlet-api.jar file

Servlet-api jar is set of java classes and interfaces implemented by sun micro system. This is one of the servlet API implementation.

If we develop any application we need this jar file. We will use many classes and interface from this jar file.This jar should be available in application class path or server global class path

What is class path?

Class path is a place where all java classes and interfaces will be available.We will use following things as class path
  1. Application WEB-INF/classes directory
  2. Application WEB-INF/lib directory
  3. Server lib directory

Application WEB-INF/classes directory

Every web application have WEB-INF/classes directory where all java compiled classes will be available. This directory is only specific to respective web application. If any class available in WEB-INF/classes directory will be loaded by server in the JVM memory as soon as application is deployed in server.

Application WEB-INF/lib directory

WEB-INF/lib another class path for server here all required jar files will be placed. The jars which are available in WEB-INF/lib directory will be used by respective application. These are application specific jar files.

Server lib directory

Server lib directory is called global class path this directory shared by all web application which are deployed in server. Any jar file or java class available in server lib then it is available to all applications.

Note:

Server global class path or global lib will be varied based on server.

If any jar file available in server global class path that particular jar should not be available in application class path if such cases we will get class conflicts.

For tomcat it will be tomcat-7.0.40\lib this is default directory for tomcat and we can also change this by configure the details in catalina.properties.

Application Class path priority


WEB-INF/classes > WEB-INF/lib > Server lib directory


Servlet Container Provider Servers (Tomcat)

Servlet container is required to run servlet. This container is responsible for manage the life cycle of servlet.

Servlet container can be provided by different server vendors by default. So we can run servlet application in any server if the server have servlet container.

Tomcat is one of servlet which provide the servlet container. We will use tomcat server to run servlet based web applications.

Servlet Execution Flow
  • We already know servlet information is available in web.xml file.
  • When the application is deployed in the server then servlet container is responsible to read all servlets information from web.xml file
  • In web.xml file servlet name and its URL mapping will be available. Servlet container will create servlet mapping objects in the server memory that object contains servlet URL pattern and its respective servlet class.
  • When client is requested through http URL and the URL will have servlet mapping pattern.
  • As soon as server receives the request from client then server will delegate the request to servlet container because the request is dynamic request.
  • As soon as request received by servlet container then it will check with servlet mapping objects in the server memory.
  • If any mapping object find for client request then it will get the respective servlet class information and it will create the object for servlet and it will execute the appropriate methods on behalf of servlet object.
  • These servlet methods are responsible to prepare dynamic response in the form of html or other browser understandable format.
  • Once response preparation is completed then servlet container collect the response data from servlet then the container give the response back to server.
  • As soon as server gets the response from container then it will give to client then client will display response in browser so that it is able to viewed user.

Request for servlet/Call servlet:

In web application we need to request to the servlet in particular URL pattern

The following is generic URL request to servlet


http://<hostName>:<port Number>/<application context>/<servlet url pattern>

Example:

http://localhost:8080/myapp/helloWorl


Host Name:

Host name is name of computer or domain name where server is running.

If we run in server in local computer then it is localost/127.0.0.1

If server is running in local area net work or in the internet then we will have domoan name or IP address

Example:

198.168.34.23

Application Context:

Application context is name of our web application name. this is our application start point.
We can see the application context name in server deployments directory in general application name itself is application context.

Example:  MyApp

Note:

Application Name/Context name should not have spaces or special characters.

Servlet URL pattern:

Servlet URL pattern is simple string which will used in client requested URL. We need to append servlet URL pattern to client request so that servlet container can identify the servlet and it will be executed. Servlet URL pattern we can see in web.xml file.

Example configuration in web.xml

<servlet-mapping>
    <servlet-name>helloWorldServlet </servlet-name>
    <url-pattern>/helloworldservlet </url-pattern>
 </servlet-mapping>


Related Articles


Reference links for Servlet Technology and its Development


Author

Monday, January 20, 2014

Introduction to Web Applications Part-II

Introduction:

We already know web application can be categories into two types
  1. Static web applications
  2. Dynamic Web Applications

Go through following links to web application introduction part  I


Static Web Applications

A static web application deliver response to user what exactly stored in server. The response is always same for all users when they requested to server. It means static html pages, pdf files and images.

These resources are available in server so that when the user requested to server and the server will serve as response. The user will be requested as simple http request to the server so that server will serve the static recourses as response. To handle request and manage these recourse we will use web server.

What is web server?

A web server is server to handle or process the http request and serve the response to the end users.

We already know http request is simple URL and it will ask the web server for response on behalf of user.

The popular web server in the market is Apache Web Server. In the world most of the web servers are Apache Web servers


For example we will request for one html page that html page contains the company information.


When we send above request to the web server it will always give the static data which is presented in requested html page. It means the response data always same for all user requests.
.

The following is more information about Apache Http server


The final bottom line is static web applications always serve same response to users and to manage these static web applications we will use web servers.

Dynamic Web Application

Dynamic web application serves the response based on user demand and the response is varying based on user request.

It will generate dynamic response to end user when they request to the server. Here http request is same but based on user the content/data will be changed.

For example it will use same resource for every request but the resource will be generating the dynamic content based on user request.

We can assume we want employee information and for this each request we call same resource but it will give different employee information


If we observe above request, based on employee Id we will get different employee information but each time it will execute same resource in server.

The following diagram shows the web application in server


In above diagram user send the request to get employee information and server execute same resource and that recourse get employee data from information system and give response back to the user.

Who will produce Dynamic Response?

In dynamic web applications to produce dynamic response we need special kind of resources and these resources are called helper applications.

Helper application are kind of recourses will be executes in server to prepare dynamic response. To execute helper applications we need containers.

Helper application is server side technology to produce dynamic response based on users demand.

What is container?

Containers are managing helper applications it means it will process helper application to produce dynamic response. Processing of helper application is like execution of helper applications.

Containers are responsible for managing liferay cycle of helper application when they producing dynamic response. The example for helper application in Java is servlet

Servlet is helper appellation or server side component to produce dynamic request to the user.
To execute servlet we need servlet container. The servlet container is responsible for execution of servlet or manages the life cycle of servlet when they produce dynamic request.

We have different containers in java like servlet container, EJB container and JMS container.
Static Web application can be served by Web servers but dynamic applications cannot so that dynamic web application needs application servers.

What is Application Server?

Application server is like web server to handle http request besides that it will also manage the dynamic applications.

We already know to execute dynamic application we need containers. Application server has ability to integrate with many containers like servlet, EJB and JSM containers.

Application server is used to manage dynamic web application.

We already know we need helper application or servlet to process dynamic request. To produce dynamic response it will use some information system for getting the data. Those information systems are like databases.

Servlet need database to produces dynamic response. The response is in the form of browser understandable language that is html.

Servlet can produce response in the form of HTML or other formats like text, images and files formats but all these formats should understand by browser.

Note:

In the real environment we will use combination of Web server and Application Server

General Request flow in Dynamic Web application
  • The user/client sends the request to the server.
  • Server will identify the request whether it is dynamic request or static request.
  • If static request then web server handle the request means it will process request and produces the response.
  • If dynamic request then web server delegates the request to helper application so that helper application processes the dynamic request and it will generate the response. Helper application will take the container help to produce the response.
  • The response will give to the web server and web server is responsible to send response to client.

The following diagram depicts the flow of dynamic request.



In java we will use servlet to process dynamic request and we use servlet to build dynamic web applications.

What is servlet?

Servlet is server side technology to produce dynamic response. Servlet will be executed in servlet containers when they produce dynamic response. Servlet container will manage the lifecycle of servlet.

Important Points
  • We have two different kinds of web applications static and dynamic.
  • Static application will be managed by web servers and dynamic applications are managed by application server.
  • To produce dynamic response we need helper applications and these helper application need container to execute and produce response.
  • Helper application is server side technology and example in java is servlet.
  • Application server has ability to accommodate different container like servlet, EJB and JMS containers.
Related Articles



Author
Liferay Top Contributor Award Winner

Wednesday, January 15, 2014

Introduction to Web Applications Part-I

Introduction:

A web application is set of resources which will be available in universally. Resources are like files, images and any data which is informative.

Each web application has its own unique location in the internet so that we can access the web application.

To represent any web application in internet we will use domain or IP address this is called address of application. This address is unique in the web world or internet which gives you the destination point of web application.

When we talk about web application we need to consider two things that are Server and Client.
As we know web application have destination point these destination point is server. Server is one kind of software which manages the web application. A client is requesting for server to get response from server.

Web application is implemented by Client Server Architecture.

Client Server Architecture:


Client server architecture is working based on request and response mechanism. Client is always request for the server to get response. The response is like file, images or data.
We know response is generated by server and request is send by client.

What is client in real world?

In internet world a client is software which is able to send request to the server. Once it gets server response it should able to view the response to real world. Here we can say client is able to view the response and response consist of images, files and data.

In web application world a client is web browser. We are very familiar with web browser so some web browsers like Internet Explorer, Mozilla Fire Fox and Chrome.

So the bottom line is client is web browser that can send request to server and it can view the service response to out side world.

What is server in real World?

A server is also software which manages the web application that means it is managing resources. It is always serving the response to the client when client sends request to server. We have many servers in real world like Apache server, Tomcat Server and JBoss server.

Well we understand server and client.

Client Server Communication

We are talking client sends request and serve will give the response to client. How the request will be sent to server and how response will be reached by client.

We need a language that should communicate client and server. That language should understand by both server and client.

This language is called HTTP. Http is mechanism which will used to communicate client and server.

Hyper Text Transfer Protocol (http) is making the communication between client and server and it has some set of rules that will be followed by client and server.

In the real world http is like URL it represent the client request. Http can understand by only client that’s web browser and server.

Whenever client needs some resource or data it will send his request in the form of URL. This URL request can be understand by server so that it will send required response to the client based on what client is looking for.

Each URL request has some parameters these parameters will be decide what kind of response should be generated by server.

How client can display response?

In web world client is web browser how do browser can view the server response, here we need some specialize language that should be understand by browser the language is called HTML.
HTML is way of view the response in browser. The browser can understand only one language called Hyper Text Markup Language (HTML) so that server which is going to send to the browser should be HTML format.

Apart from HTML browsers can display different format data like images, PDF and some file formats. The default response format is always HTML format.

What is HTML?

HTML is specialize language for web browsers. It is tag based language it have many tags to display data in browsers.

The more about HTML go through following link


Html is just tag based language it only show the content in the page but if we want perform some actions or events in the browser it will use another language that is called scripting language.
Scripting languages are specialize languages for browser so that  we can perform some actions and events in the web page.

Java Script is very popular scripting language for the web browsers.

The following link will give more information about java script


We already know HTML can view the response in browser to real world people. The data which we displayed in the browser need some styles or colors so that it will be better look and feel to people.

To make content beautiful in the browser we need some other language that is called Cascading Style Sheets (CSS)

CSS will give better look and feel to the data so that I will be attractable.

The following is more about CSS


The bottom line is the response is in the form of HTML and html data need some other languages support to make content beautiful and perform some action in browser for this reason we need another languages like CSS and Java Script.

Well we have good understanding about web application and it working in real world.

In real world web application can categorized in two types
  1. Static Web Applications
  2. Dynamic Web Applications
We will discuss more in the next part of my articles

Author

Recent Posts

Recent Posts Widget

Popular Posts