SlideShare a Scribd company logo
1 of 67
• In a broad term, an enterprise means a business
organization. The functionality of the organization
may limited to one single unit or may be distributed
over multiple units and possibly units are situated at
geographically different location. Also different unit
follows different policies and rules. To manage these
diversities with automation requires lot of effort. One
single bug can harm the organization.
•

Each business organization has its own set of
rules and policies

•

Organization may have different set of activities

•

An enterprise programming facilitate various
activities in an enterprise by following rules and
policies.

•

In another word, enterprise application are one
which helps an enterprise to manage its various
activities.
•

A well designed E-app must meet the
following goals:

•

Robustness : - Should have no or less
number of bugs.

•

Scalability and Performance :- Scalability
refers to the term that the potential for an
application to support increased load, given
the appropriate hardware. The E-app must
be designed in such a manner that it should
not degrade its performance if load
increases suddenly.

•

Maintainable & extensible : - A well
designed E-app should be easy
maintainable. If bugs are reported the it
should be removed easily.

Also new features can be added easily.
Followings are the advantage of JAVA in Eprogramming
•

Platform Independent : - Wide ranging
scattered enterprise information that too in
disparate formats are available that may be
spread across different platform. So we
need to adopt a programming language
which function evenly well throughout the
enterprise.

•

Managed Object :- JEE application are
container centric. Due to this property, JEE
component utilize the infrastructure provided
by the JEE server without the programmer
being aware of it.

•

Reusability : - Java is OO language. Objects
can be reused in many different ways to
achieve different functionalities.

•

Modularity :-
A software application composition can be broken
down into three fundamental concerns or logical
layers.
•

The UI : - This is responsible for displaying
stuff to the user and collecting data from the
user. Also called Presentation Layer.

•

Processing:- In this layer, the application works
and handles the important processing. This
logical layer is called Business rule layer.

•

Data Storage land Access : - All non-trivial
business applications need to read and store
the data. The part of the software that is
responsible for writing data to the source and
reading it from the source is called Data
Access Layer.

On the basis of deployment of these three layers,
the E-app can have the following architecture
The UI

The Business Rule

Data Access

THE SINGLE TIER ARCHITECTURE
•

All the concerns are deployed on a single
machine.

•

Strictly for single user

•

Easy to develop and maintain.

 Multiple user support is not available
 Hard to share data across enterprise.
The UI

Request

Data Access

The Business Layer

The 2 tier architecture
•

Data can be shared between multiple users.

•

Multi-user system

 The centralized database system may be
the bottleneck.
 The client side resource consumption is very
high and so the client is called FAT client.
The UI

Request

Request

Data Access

Response

The Business Layer

Response

The 3 tier architecture
•

Data can be shared between multiple users.

•

Multi-user system

•

Less number of resource is consumed on
client side and hence client is called THIN
client.

•

Easy for maintenance.

•

Extendable

 There is no clear separation between
presentation and logic. So hard to develop.
C1
EJB container

C3

C2

EIS

Web Container
In JEE app, containers are the central theme. A
container provides the runtime environment for
various component of JEE apps. It acts as a
runtime interface between the application
components and the low level platform specific
functionalities. The JEE containers provides
development, management and execution
support for application components.
There are four types of container
1. EJB Container : It manages the execution
of all the enterprise bean for one JEE
application.
2. Web Container : A web container manages
the execution of all JSP pages and servlet
for one JEE application.
3. Application Client Container : It manages the
execution of all application client component
for one JEE application.
4. Applet Container : It is a combination of web
browser and java plug-in running together
on the client machine.
HTTP is also known as Hyper-Text Transfer
Protocol. It is an application level protocol. It is
the mode by which web pages are
communicated across the internet.
Normally this protocol is used in communication
between client and the server. Here are the
steps followed in this protocol:
1. Connect
2. Request
Client

3. Response
4. Close

Server
A HTTP transaction begins with a request from the client’s
browser and ends with a response from the server. The
HTTP request consists of three components :
1.

Method URI

2.

Request Header

3.

Protocol/Version

Entire Body

Example
GET /servlet/default.jsp HTTP/1.1
Accept : text/plain ; text/html
Accept-Language : en-gb

Connection : Keep-Alive
HOST : localhost
User-Agent : Mozilla/4.0(Compatible; MSIE 4.01; windows
98)
Content-Length : 33
LastName=Saurabh&FirstName=Atul
Whenever client need to send some request to
the server it uses some HTTP specific method.
HTTP 1.0 defines only two methods GET and
POST. HTTP 1.1 defines five more.
Method

Description

GET

GET is the simplest
and most used
method. GET simply
retrieves the data
identified by the URI.

HEAD

This is similar to GET
but it only retrieves
the HTTP header and
not the body.
Method

Description

POST

It is normally used in
HTML forms. Post is
used to transfer a block
of data to the server in
the entire body of the
request

OPTIONS

The OPTIONS method
is used to query a server
about the capabilities it
provides.

PUT

It is complementary of
GET. It stores the entire
body at a location
specified by the URI.
Method

Description

DELETE

This method is used to
delete a document from
the server. The
document is identified
by the URI.

TRACE

It is used to trace the
path of the request
through firewall and
multiple proxy server.
Similar to HTTP Request , HTTP response
consists of three parts:
1. Protocol Status code Description
2. Response Header

3. Entire Body
Example
HTTP/1.1 200 OK
Server : Microsoft IIS/4.0
Date : Mon 3, jan 2007 13:34:60 IST
Content-Type : text/html
Content-Length : 112

<html> <head><title>Example</title></head>
<body>Welcome</body></html>
Client

Machine

Prepare
HTTP
Request

port
Convert
response object
to HTTP
response

Process &
Prepare response
Object

Server

Container

Request
Convert to
object
A servlet is a java based server side
technology runs inside a container called
servlet engine.
Servlet interacts with client via a requestresponse model based on HTTP.
For programming perspective a servlet is
defined in two ways:
1. A servlet is a java class embedded with
HTML code.
2. A servlet is a java class which extends
javax.servlet.http.HttpServlet class.
From the definition it is clear that a servlet is a
java class. So,
import javax.servlet.http.HttpServlet;

public class MyServlet extends HttpServlet
{
}
Receive
Request

Is
servlet
loaded

no

yes

Is
servlet
current

yes
Process request

no

Load Servlet
Send Response
Receive
Request

Is
servlet
loaded

no

yes

Is
servlet
current

No request for long
time
Call destroy()

yes

no

Call init()
Call Service()

Load Servlet

Send Response
JEE application requires a certain fixed directory
structure so that the server can identify and
locate resources in the app. Some names are
reserved and must not use elsewhere. Some of
the directories are mandatory and some are
optional. Here is the structure:
Root(M)
Reserved(M)
Reserved(M)
Important(M)

Required for
specific
purpose(O)
1. The Root :- The name of root directory is NOT
reserved. It depends upon the project name
possibly.
2. WEB-INF : - Its name is reserved and must be
located inside the root directory. It is a private
directory.
3. WEB-INF/classes : It contains all the java
classes.
4. WEB-INF/web.xml : It is called deployment
descriptor.
5. WEB-INF/lib : It contains all the external
libraries possibly in form of JAR.
6. META-INF : It is optional. But it name is
reserved. It contains project related
configuration file.

All the JSPs, HTML, JS, CSS etc go inside root
directory.
The following are the steps required to run a servlet.
Step -1 : Write a Servlet

import javax.servlet.http.*;
import java.io.*;
import javax.servlet.*;
public class MyServlet extends HttpServlet
{
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException,
ServletException
{
PrintWriter out=response.getWriter();
out.println(“Hello World!!!”);
}
}
Step -2 : Compile The Servlet
set
CLASSPATH=%CATALINA_HOME%commonlibservlet.j
ar;.
javac MyServlet.java
OR
javac classpath
%CATALINA_HOME%commonlibservlet.jar
MyServlet.java
Here CATALINA_HOME represents the installation
directory of Apache Tomcat.
Step -3 : Create the directory structure for the project. The
root folder may have name Test.

Step -4 : Put the servlet class in the WEB-INFclasses
directory.

Step -5 : Create the deployment descriptor i.e. web.xml
and put the following content in this file….
<!DOCTYPE web-app PUBLIC “-//Sun Microsystem,Inc.//
DTD Web Application 2.3//EN”
http://java.sun.com/dtd/web-app_2_3.dtd>
<web-app>
<servlet>
<servlet-name>Sample</servlet-name>
<servlet-class>MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Sample</servlet-name>
<url-mapping> /Sample</url-mapping>
</servlet-mapping>
</web-app>
Step -6 : put the web.xml inside WEB-INF folder.
Step -7 : put the whole directory structure inside
%CATALINA_HOME%web-apps
Step -8 : Run the apache server using
%CATALINA_HOMEbinstartup.bat

Step -9: Call the servlet from the browser
http://localhost:8080/Test/Sample
Here
is
the
class
javax.servlet.http.HttpServlet

Hierarchy

javax.servlet.Servlet
implements
javax.servlet.GenericServlet
extends
javax.servlet.http.HttpServlet

of
HttpServlet class gets Life-cycle method from
GenericServlet class and GenericServlet provides
implementation of all method present inside Servlet
interface. Here are the methods defined in Servlet
interface
•

public void init(ServletConfig config) throws
ServletException

•

public void service ( ServletRequest request,
ServletResponse response) throws IOException,
ServletException

•

public void destroy()

•

public String getServletInfo()

•

public ServletConfig getServletConfig()
The HttpServlet is basically used to handle HTTP
Request.
So HttpServlet defines some of the methods related to
HTTP. Here are some of those methods….
1. protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws IOException,
ServletException
2. protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws IOException,
ServletException
3. protected void doDelete(HttpServletRequest request,
HttpServletResponse response) throws IOException,
ServletException
When a HTTP client sends a request using any HTTP
method (GET, POST, DELETE…) then the servlet engine
calls corresponding doXXX method. As for example when
the client sends a request using DELETE HTTP method
then servlet engine call doDelete method. Notice that all
doXXX methods are very similar to service method. Here
are the steps in handling request using servlet….
1. The server get a request from the client.
2. The server converts the HTTP request into
ServertRequest and handed over to the container.
3. The container invoke the servlet mapped by the URI.
4. The container create a thread for each client and the
thread calls the service method. The ServletRequest
object is handed over to the service method.
5. The service method in turns downcast the
ServletRequest into HttpServletRequest and calls the
doXXX method.
Whenever client need to send some useful information to
the server then the message is sent in form of
Key=value
format. As form example

firstname=rahul
Here firstname is the key and rahul is the value.
If there are many messages then each one is seperated
by &. As for example

firstname=rahul & lastname=dutta
The HttpServletRequest parameter to the doXXX
method represents the request sent by the client. This
interface provides useful methods to fetch all the
parameters sent by the client.
Here are the methods provided by the
HttpServletRequest interface.
Sl. No

Method Signature

Description

1.

String getParameter(String key)

Returns the value
associated with the
key. Useful when one
key is associated with
one value only. E.g.
fetching the value
submitted through the
textfield, Dropdown
box etc in HTML.

2.

String []
getParameterValues(String key)

Returns the array of
values associated with
the key. Useful when
one key is associated
with multiple values.
E.g. fetching values
from HTML checkbox.
Sl. No

Method Signature

Description

3.

Enumeration
getParameterNames()

Returns all the keys
sent by the client. This
method can be used in
conjunction with
getParameter or
getParameterValues.

4.

RequestDispatcher
getRequestDispatcher(String
pageName)

Returns
RequestDispatcher
object to either include
the page referred by
pageName in the
current page or
forward to page.
Sl. No

Method Signature

Description

5.

String getMethod()

Return the HTTP i.e.
GET, POST etc.
method using that this
request is sent.

6.

String getRequestURI()

Returns the URI
associated with this
request.
Sl. No

Method Signature

Description

7.

String getHeader(String
hname)

Return the value of the
header represented by
hname.

8.

Enumeration
getHeaderNames()

Returns the names of
all the headers sent by
the client
Sl. No

Method Signature

Description

7.

InputStream getInputStream()

Return the inputstream
object if the request
contains some binary
data.

8.

HttpSession getSession()
HttpSession
getSession(boolean create)

Returns the session
object associated with
the current request.
import javax.servlet.*;
import javax.servlet.http.*;
2
import java.io.*;
public class CheckBoxHandler extends HttpServlet
{
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws IOException,
ServletException
{
PrintWriter out=response.getWriter();
String choices[] =
request.getParameterValues(“myChoice”);
out.println(“You have selected…<br>”);
for(int i=0; i< choices.length;i++)
{
out.println(“ “+choices[i]+”<br>”);
}
}
}
Compile the servlet… Put it at correct place inside the
directory structure. Map it inside web.xml and then create
an HTML form
<body>
<form method=“POST” actoin=“chkboxhndlr”>

3

<lable>Cricket</label><input type=“checkbox”
value=“cricket” name=“myChoice”/>
<lable>Basket Boll</label><input type=“checkbox”
value=“basketboll” name=“myChoice”/>
<lable>Hockey</label><input type=“checkbox”
value=“hockey” name=“myChoice”/>
<button type=“submit”>Submit</button>
</form>
</body>
The mapping in web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app … >

1

2
<servlet>
<servlet-name>setServlet</servlet-name>
<servlet-class> CheckBoxHandler </servlet-class>
</servlet>
1

<servlet-mapping>
<servlet-name>setServlet</servlet-name>
<url-pattern>/ chkboxhndlr </url-pattern>
</servlet-mapping>

</web-app>

3
Sometimes it is required to initialize the servlet with some
parameters so that when the servlet is up and running the
parameters are available to it. This is generally called the
configuration of the servlet and is limited to one servlet in
context.
The servlet is configured in web.xml i.e. Deployment
Descriptor using <init-param> tag. Here is the code snippet :

<servlet>
<servlet-name>abc</servlet-name>
<servlet-class>org.MyServlet</servlet-name>
<init-param>
<param-name>Nname</param-name>
<param-value>Atul</param-value>
</init-param>
</servlet>

A
The initialization parameters are available to the servlet via
ServletConfig object. The GenericServlet override all the
abstract method of Servlet interface. And HttpServlet class
extends GenericServlet class. So the ServletConfig object
can be obtained using getServletConfig() method. One can
use getInitParameter(…) method to obtain the initial
configuration values. Here is the code snippet.
The servlet is configured in web.xml i.e. Deployment
Descriptor using <init-param> tag. Here is the code snippit :
protected void doGet(…… req, …..res) ….
{
ServletConfig g=getServletConfig();
String nName=g.getInitParameter(“Nname”);
………
}

A
Here are the methods defined ServletConfig interface
Sl. No.

Method

Description

1.

String getInitParameter(String key)

Returns the values
associated with key

2.

Enumeration
getInitParameterNames()

Returns all the keys
defined for the
configuration of this
servlet

3.

ServletContext getServletContext()

Returns the context
object for this servlet
The context represents the run time environment in which
the servlet is running. The context is represented by the
ServletContext object. Sometimes we need the set the
configuration of all servlet running in an environment. That
means the configuration is not limited to one particular
servlet but available to all. In that case we need to talk to
runtime environment and ServletContext will help. The
initial configuration is also set in web.xml.

Here is the way:
<web-app>
<context-param>

B

<param-name>forAll</param-name>
<param-value>Good Morning</param-value>
</context-param>
……
</web-app>
Note that the <init-param> is not written inside any
<servlet> tag. Here is the way to obtain the initial
parameter

protected
………

void doGet(…… req, …….res)

{
ServletConfig g=getServletConfig();
ServletContext c=g.getServletContext();
String msg=c.getInitParameter(“forAll”);
………………..
}

B
Here are some of the useful methods defined in
ServletContext interface.
Sl. No

Method

Description

1.

String getInitParameter(String key)

Returns the initial
parameters
associated with the
key set for the
servlets.

2.

Enumeration
getInitParameterNames()

Returns keys for all
initial parameters set
for the servlet.

3.

RequestDispatcher
getNamedDispatcher(String
pageName)

Returns the
RequestDispatcher
object for moving or
including the page
identified by
pageName
Sl. No

Method

Description

4.

void setAttribute(String
attribName,Object attrib)

Set the attribute to
the session

5.

Object getAttribute(String
attribName)

Returns the attribute
associated with the
attribName.

6.

RequestDispatcher
getRequestDispatcher(String
pageName)

Returns the
RequestDispatcher
object for moving or
including the page
identified by
pageName
HTTP is a stateless protocol. That means the server is not
going to maintain any state of the client and every request
from the client is considered as the fresh request. But in
some situation like Book Shopping it is necessary to
maintain the state of the client because a client may add
some book to its own cart.
The state of client is loosely called its session. More
precisely a session is defined as
“A session is an uninterrupted request-response
series between a client and the server”.
The uninterrupted does not mean that client need to send
the request immediately after it gets the response. Of
course there might be a relaxation of time. But the server
expect that client must communicate with it within the time
limit.
Mainly in E-app programmer use two technique to
maintain the session.
i)

Cookie

ii)

HttpSession

The Cookie
The cookie is a small text file in which the server keeps
some information related to the client session and store
on the client local hard disk. Here are the steps when
session is managed by cookie.
1) The server prepare a cookie at some point of time and
add it to the response. That means when the client
browser get some response it also get the cookie. The
browser store the cookie at its local hard disk. Normally
the server stores time span, date of creation etc.
information in the cookie.
Here is piece of code……

protected void doGet(…. Req, …. Res ) …….
{
Cookie c=new Cookie(“MyCookie”,”Add Cart”);
Res.addCookie(c);
}
2) Next time when the browser sends a request to the
server, it also sends the cookie to the server. Now it’s the
duty of the server to get cookie from the request and
perform some analysis task (possibly).
protected void doGet(…. Req, …. Res ) …….
{
Cookies [] c=Req.getCookies();
for(int i=0;i<c.length;i++)
{
Cookie c1=c[i];
String value=c1.getValue();

}
}
Here are some useful method in cookie class.
Sl. No

Method

Description

1.

void setMaxAge(int exp)

Set age for cookie in
seconds

2.

void setValue(String value)

Set the value in
cookie

3.

int getMaxAge()

Return the life span of
the cookie in seconds

4.

String getValue()

Returns the value set
in the cookie.
•

The cookie is always stored at client side. That is why
the resources at server side is saved.

•

Cookie is a small textual information which requires
less bandwidth to travel back and forth.

•

It is always a chance that client may change the data
written inside the cookie. So not reliable.

•

If the Cookie is deleted, by accident also, the session
will be invalidated by the server.
Cookie saves the server resources but gives a strong
chance to the client to control the session. This
disadvantage make the cookie impractical to maintain
cookie.
Java provides one more mechanism to maintain client
session. And the mechanism is HttpSession. HttpSession
does not allow the client to control the session. The server
has full control over the client’s session.
Whenever client need to session start, the sever generate
a unique id called session id. This session id is sent back
to the client. Whenever the client send request to the
server it also sends it own session id. The server then
verify the session id against its own repository. If the id is
valid and not invalidated the server provides the allocated
resource to the client.
HttpSession is an interface in javax.servlet.http
package. When the client first interact with the server it
does not have the session id. The server tries to fetch the
session id from the request. If the id is NOT available then
the server will create a session object and generate the
session id. And that is why the HttpServletRequest
interface provides two method to retrieve and create the
session.
Sl. No.

Method Name

Description

1.

HttpSession getSession()

Always create a new
session object. It
does not check
whether session id is
present or not

2.

HttpSession getSession(boolean
create)

If the create is true
then a new session
object is created.
Otherwise the session
object is retrieved
from the request.
Here is the code snippet to show how to create a session.

protected void doGet(…… request, ….. response)
throws ….
{
// If this is the first request for maintaining the
sesion.
HttpSession s=request.getSession(); // A session
object is created and id is generated.
.
.
.

}
Here is the code snippet to show how to create a session.

protected void doGet(……
response) throws ….

request,

…..

{
// for subsequent request from client
HttpSession s=request.getSession(false); // An
old session is fetched from the request.
.
.
.

}
The HttpSession interface provides some important
methods.

Sl. No.

Method Name

Description

1.

void setAttribute(String key,
Object value)

Set any java object
in the session
object. This java
object will remain in
the session until
either session is
invalidated or server
explicitly call
removeAttribute

2.

Object getAttribute(String
key)

Returns the java
object set in the
session with key.
Sl. No.

Method Name

Description

3.

void removeAttribute(String
key)

Remove the object
associated with key
from the session
object.

4.

void
setMaxInactiveInterval(int
age)

This method set the
maximum time span
in seconds for which
the client may
remain inactive. If
the time span laspe
the session object is
destroyed.

5.

void invalidate()

Forcefully destroy
the session.
JEE framework two ways to set the inactive age for the
session object.
1. Using the setMaxInactiveInterval(int age) method of
HttpSession interface. Example :

protected void doGet(……. req, ……. resp) throws
….
{
HttpSession hs = req.getSession();
hs.setMaxInactiveInterval(3* 60); // set the
inactive age of session as 3 min.
}
This configuration is available to one type of session. It
is possible that other client may have different setting
for session object.
2. Using web.xml

<web-app…..>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
</web-app>
Here the 30 represent 30 min and NOT 30 sec. This
configuration is valid for every session object.

More Related Content

What's hot

Informatica Power Center - Workflow Manager
Informatica Power Center - Workflow ManagerInformatica Power Center - Workflow Manager
Informatica Power Center - Workflow ManagerZaranTech LLC
 
ISV Integrations
ISV IntegrationsISV Integrations
ISV Integrationsmufflerdog
 
Case Management by EMC - xCP Platform
 Case Management by EMC - xCP Platform Case Management by EMC - xCP Platform
Case Management by EMC - xCP PlatformAmplexor
 
VMworld 2013: Moving Enterprise Application Dev/Test to VMware’s Internal Pri...
VMworld 2013: Moving Enterprise Application Dev/Test to VMware’s Internal Pri...VMworld 2013: Moving Enterprise Application Dev/Test to VMware’s Internal Pri...
VMworld 2013: Moving Enterprise Application Dev/Test to VMware’s Internal Pri...VMworld
 
Spstc2011 Developing Reusable Workflow Features
Spstc2011   Developing Reusable Workflow FeaturesSpstc2011   Developing Reusable Workflow Features
Spstc2011 Developing Reusable Workflow FeaturesMichael Oryszak
 
TFS 2013 Care and Feeding
TFS 2013 Care and FeedingTFS 2013 Care and Feeding
TFS 2013 Care and FeedingAngela Dugan
 
Define and Manage Requirements with IBM Rational Requirements Composer
Define and Manage Requirements with IBM Rational Requirements ComposerDefine and Manage Requirements with IBM Rational Requirements Composer
Define and Manage Requirements with IBM Rational Requirements ComposerAlan Kan
 
Prateek sharma etl_datastage_exp3.9yrs_resume
Prateek sharma etl_datastage_exp3.9yrs_resumePrateek sharma etl_datastage_exp3.9yrs_resume
Prateek sharma etl_datastage_exp3.9yrs_resumePrateek Sharma
 
ASP.NET Core For The Agile Enterprise
ASP.NET Core For The Agile EnterpriseASP.NET Core For The Agile Enterprise
ASP.NET Core For The Agile EnterpriseDennis Moon
 
Peoplesoft PIA architecture
Peoplesoft PIA architecturePeoplesoft PIA architecture
Peoplesoft PIA architectureAmit rai Raaz
 
Stldodn 2014 TFS Care and Feeding
Stldodn 2014 TFS Care and FeedingStldodn 2014 TFS Care and Feeding
Stldodn 2014 TFS Care and FeedingAngela Dugan
 
BPEL, BPEL vs ESB (Integration)
BPEL, BPEL vs ESB (Integration)BPEL, BPEL vs ESB (Integration)
BPEL, BPEL vs ESB (Integration)ejlp12
 
Key challenges in flex based performance testing
Key challenges in flex based performance testingKey challenges in flex based performance testing
Key challenges in flex based performance testingPhanindra Kishore
 
Lotus notes app migration process v1.2
Lotus notes app migration process   v1.2Lotus notes app migration process   v1.2
Lotus notes app migration process v1.2Officience
 
Chicago Code Camp 2014 TFS Care and Feeding
Chicago Code Camp 2014   TFS Care and FeedingChicago Code Camp 2014   TFS Care and Feeding
Chicago Code Camp 2014 TFS Care and FeedingAngela Dugan
 
A Smart Strategy for Windows Server 2003 Migration
A Smart Strategy for Windows Server 2003 MigrationA Smart Strategy for Windows Server 2003 Migration
A Smart Strategy for Windows Server 2003 MigrationFlexera
 
A Software Engineering Perspective on SDN Programmability
A Software Engineering Perspective on SDN ProgrammabilityA Software Engineering Perspective on SDN Programmability
A Software Engineering Perspective on SDN ProgrammabilityFelipe Alencar
 
Vs2008 to improve Development
Vs2008  to improve DevelopmentVs2008  to improve Development
Vs2008 to improve Developmentmaddinapudi
 
Tips & Tricks to build software architecture document
Tips & Tricks to build software architecture documentTips & Tricks to build software architecture document
Tips & Tricks to build software architecture documentKarthikeyan VK
 

What's hot (20)

Informatica Power Center - Workflow Manager
Informatica Power Center - Workflow ManagerInformatica Power Center - Workflow Manager
Informatica Power Center - Workflow Manager
 
ISV Integrations
ISV IntegrationsISV Integrations
ISV Integrations
 
Case Management by EMC - xCP Platform
 Case Management by EMC - xCP Platform Case Management by EMC - xCP Platform
Case Management by EMC - xCP Platform
 
VMworld 2013: Moving Enterprise Application Dev/Test to VMware’s Internal Pri...
VMworld 2013: Moving Enterprise Application Dev/Test to VMware’s Internal Pri...VMworld 2013: Moving Enterprise Application Dev/Test to VMware’s Internal Pri...
VMworld 2013: Moving Enterprise Application Dev/Test to VMware’s Internal Pri...
 
Spstc2011 Developing Reusable Workflow Features
Spstc2011   Developing Reusable Workflow FeaturesSpstc2011   Developing Reusable Workflow Features
Spstc2011 Developing Reusable Workflow Features
 
TFS 2013 Care and Feeding
TFS 2013 Care and FeedingTFS 2013 Care and Feeding
TFS 2013 Care and Feeding
 
Define and Manage Requirements with IBM Rational Requirements Composer
Define and Manage Requirements with IBM Rational Requirements ComposerDefine and Manage Requirements with IBM Rational Requirements Composer
Define and Manage Requirements with IBM Rational Requirements Composer
 
Prateek sharma etl_datastage_exp3.9yrs_resume
Prateek sharma etl_datastage_exp3.9yrs_resumePrateek sharma etl_datastage_exp3.9yrs_resume
Prateek sharma etl_datastage_exp3.9yrs_resume
 
ASP.NET Core For The Agile Enterprise
ASP.NET Core For The Agile EnterpriseASP.NET Core For The Agile Enterprise
ASP.NET Core For The Agile Enterprise
 
Peoplesoft PIA architecture
Peoplesoft PIA architecturePeoplesoft PIA architecture
Peoplesoft PIA architecture
 
Stldodn 2014 TFS Care and Feeding
Stldodn 2014 TFS Care and FeedingStldodn 2014 TFS Care and Feeding
Stldodn 2014 TFS Care and Feeding
 
BPEL, BPEL vs ESB (Integration)
BPEL, BPEL vs ESB (Integration)BPEL, BPEL vs ESB (Integration)
BPEL, BPEL vs ESB (Integration)
 
Key challenges in flex based performance testing
Key challenges in flex based performance testingKey challenges in flex based performance testing
Key challenges in flex based performance testing
 
Homestead Weather workshop
Homestead Weather workshopHomestead Weather workshop
Homestead Weather workshop
 
Lotus notes app migration process v1.2
Lotus notes app migration process   v1.2Lotus notes app migration process   v1.2
Lotus notes app migration process v1.2
 
Chicago Code Camp 2014 TFS Care and Feeding
Chicago Code Camp 2014   TFS Care and FeedingChicago Code Camp 2014   TFS Care and Feeding
Chicago Code Camp 2014 TFS Care and Feeding
 
A Smart Strategy for Windows Server 2003 Migration
A Smart Strategy for Windows Server 2003 MigrationA Smart Strategy for Windows Server 2003 Migration
A Smart Strategy for Windows Server 2003 Migration
 
A Software Engineering Perspective on SDN Programmability
A Software Engineering Perspective on SDN ProgrammabilityA Software Engineering Perspective on SDN Programmability
A Software Engineering Perspective on SDN Programmability
 
Vs2008 to improve Development
Vs2008  to improve DevelopmentVs2008  to improve Development
Vs2008 to improve Development
 
Tips & Tricks to build software architecture document
Tips & Tricks to build software architecture documentTips & Tricks to build software architecture document
Tips & Tricks to build software architecture document
 

Similar to The java enterprise edition (Servlet Basic)

Intorduction to struts
Intorduction to strutsIntorduction to struts
Intorduction to strutsAnup72
 
Project report for final year project
Project report for final year projectProject report for final year project
Project report for final year projectsuneel singh
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts frameworks4al_com
 
Spring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsSpring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsmichaelaaron25322
 
Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2sandeep54552
 
enterprisejavaunit-1chapter-2-210914075956.pdf
enterprisejavaunit-1chapter-2-210914075956.pdfenterprisejavaunit-1chapter-2-210914075956.pdf
enterprisejavaunit-1chapter-2-210914075956.pdfEidTahir
 
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2Atharva Jawalkar
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2divzi1913
 
J2EE Notes JDBC database Connectiviy and Programs related to JDBC
J2EE Notes JDBC database Connectiviy and Programs related to JDBCJ2EE Notes JDBC database Connectiviy and Programs related to JDBC
J2EE Notes JDBC database Connectiviy and Programs related to JDBCChaithraCSHirematt
 
Java Training in Chennai
Java Training in Chennai Java Training in Chennai
Java Training in Chennai raj esaki
 
Resume_abir
Resume_abirResume_abir
Resume_abirAbir De
 
SathishKumar Natarajan
SathishKumar NatarajanSathishKumar Natarajan
SathishKumar NatarajanSathish Kumar
 
Application hardening, Secure Socket Layer(SSL) & Secure Electronic Transacti...
Application hardening, Secure Socket Layer(SSL) & Secure Electronic Transacti...Application hardening, Secure Socket Layer(SSL) & Secure Electronic Transacti...
Application hardening, Secure Socket Layer(SSL) & Secure Electronic Transacti...Jayesh Naik
 

Similar to The java enterprise edition (Servlet Basic) (20)

Java part 3
Java part  3Java part  3
Java part 3
 
Intorduction to struts
Intorduction to strutsIntorduction to struts
Intorduction to struts
 
Project report for final year project
Project report for final year projectProject report for final year project
Project report for final year project
 
Introduction to ejb and struts framework
Introduction to ejb and struts frameworkIntroduction to ejb and struts framework
Introduction to ejb and struts framework
 
Spring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applicationsSpring data jpa are used to develop spring applications
Spring data jpa are used to develop spring applications
 
Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2Enterprise java unit-1_chapter-2
Enterprise java unit-1_chapter-2
 
enterprisejavaunit-1chapter-2-210914075956.pdf
enterprisejavaunit-1chapter-2-210914075956.pdfenterprisejavaunit-1chapter-2-210914075956.pdf
enterprisejavaunit-1chapter-2-210914075956.pdf
 
Unite5-EJB-2019.ppt
Unite5-EJB-2019.pptUnite5-EJB-2019.ppt
Unite5-EJB-2019.ppt
 
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
Monolithic and Microservice architecture, Feature of Node JS 10, HTTP2
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
 
J2EE Notes JDBC database Connectiviy and Programs related to JDBC
J2EE Notes JDBC database Connectiviy and Programs related to JDBCJ2EE Notes JDBC database Connectiviy and Programs related to JDBC
J2EE Notes JDBC database Connectiviy and Programs related to JDBC
 
Java Training in Chennai
Java Training in Chennai Java Training in Chennai
Java Training in Chennai
 
JavaEE6 my way
JavaEE6 my wayJavaEE6 my way
JavaEE6 my way
 
Resume_abir
Resume_abirResume_abir
Resume_abir
 
Enterprice java
Enterprice javaEnterprice java
Enterprice java
 
SathishKumar Natarajan
SathishKumar NatarajanSathishKumar Natarajan
SathishKumar Natarajan
 
Fun Food
Fun FoodFun Food
Fun Food
 
Overview of JEE Technology
Overview of JEE TechnologyOverview of JEE Technology
Overview of JEE Technology
 
UNIT 4.pptx
UNIT 4.pptxUNIT 4.pptx
UNIT 4.pptx
 
Application hardening, Secure Socket Layer(SSL) & Secure Electronic Transacti...
Application hardening, Secure Socket Layer(SSL) & Secure Electronic Transacti...Application hardening, Secure Socket Layer(SSL) & Secure Electronic Transacti...
Application hardening, Secure Socket Layer(SSL) & Secure Electronic Transacti...
 

Recently uploaded

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin ClassesCeline George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfSanaAli374401
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.pptRamjanShidvankar
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Shubhangi Sonawane
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingTeacherCyreneCayanan
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...KokoStevan
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 

Recently uploaded (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
An Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdfAn Overview of Mutual Funds Bcom Project.pdf
An Overview of Mutual Funds Bcom Project.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
Ecological Succession. ( ECOSYSTEM, B. Pharmacy, 1st Year, Sem-II, Environmen...
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
fourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writingfourth grading exam for kindergarten in writing
fourth grading exam for kindergarten in writing
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
SECOND SEMESTER TOPIC COVERAGE SY 2023-2024 Trends, Networks, and Critical Th...
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 

The java enterprise edition (Servlet Basic)

  • 1.
  • 2. • In a broad term, an enterprise means a business organization. The functionality of the organization may limited to one single unit or may be distributed over multiple units and possibly units are situated at geographically different location. Also different unit follows different policies and rules. To manage these diversities with automation requires lot of effort. One single bug can harm the organization.
  • 3. • Each business organization has its own set of rules and policies • Organization may have different set of activities • An enterprise programming facilitate various activities in an enterprise by following rules and policies. • In another word, enterprise application are one which helps an enterprise to manage its various activities.
  • 4. • A well designed E-app must meet the following goals: • Robustness : - Should have no or less number of bugs. • Scalability and Performance :- Scalability refers to the term that the potential for an application to support increased load, given the appropriate hardware. The E-app must be designed in such a manner that it should not degrade its performance if load increases suddenly. • Maintainable & extensible : - A well designed E-app should be easy maintainable. If bugs are reported the it should be removed easily. Also new features can be added easily.
  • 5. Followings are the advantage of JAVA in Eprogramming • Platform Independent : - Wide ranging scattered enterprise information that too in disparate formats are available that may be spread across different platform. So we need to adopt a programming language which function evenly well throughout the enterprise. • Managed Object :- JEE application are container centric. Due to this property, JEE component utilize the infrastructure provided by the JEE server without the programmer being aware of it. • Reusability : - Java is OO language. Objects can be reused in many different ways to achieve different functionalities. • Modularity :-
  • 6. A software application composition can be broken down into three fundamental concerns or logical layers. • The UI : - This is responsible for displaying stuff to the user and collecting data from the user. Also called Presentation Layer. • Processing:- In this layer, the application works and handles the important processing. This logical layer is called Business rule layer. • Data Storage land Access : - All non-trivial business applications need to read and store the data. The part of the software that is responsible for writing data to the source and reading it from the source is called Data Access Layer. On the basis of deployment of these three layers, the E-app can have the following architecture
  • 7. The UI The Business Rule Data Access THE SINGLE TIER ARCHITECTURE
  • 8. • All the concerns are deployed on a single machine. • Strictly for single user • Easy to develop and maintain.  Multiple user support is not available  Hard to share data across enterprise.
  • 9. The UI Request Data Access The Business Layer The 2 tier architecture
  • 10. • Data can be shared between multiple users. • Multi-user system  The centralized database system may be the bottleneck.  The client side resource consumption is very high and so the client is called FAT client.
  • 11. The UI Request Request Data Access Response The Business Layer Response The 3 tier architecture
  • 12. • Data can be shared between multiple users. • Multi-user system • Less number of resource is consumed on client side and hence client is called THIN client. • Easy for maintenance. • Extendable  There is no clear separation between presentation and logic. So hard to develop.
  • 14. In JEE app, containers are the central theme. A container provides the runtime environment for various component of JEE apps. It acts as a runtime interface between the application components and the low level platform specific functionalities. The JEE containers provides development, management and execution support for application components.
  • 15. There are four types of container 1. EJB Container : It manages the execution of all the enterprise bean for one JEE application. 2. Web Container : A web container manages the execution of all JSP pages and servlet for one JEE application. 3. Application Client Container : It manages the execution of all application client component for one JEE application. 4. Applet Container : It is a combination of web browser and java plug-in running together on the client machine.
  • 16. HTTP is also known as Hyper-Text Transfer Protocol. It is an application level protocol. It is the mode by which web pages are communicated across the internet. Normally this protocol is used in communication between client and the server. Here are the steps followed in this protocol: 1. Connect 2. Request Client 3. Response 4. Close Server
  • 17. A HTTP transaction begins with a request from the client’s browser and ends with a response from the server. The HTTP request consists of three components : 1. Method URI 2. Request Header 3. Protocol/Version Entire Body Example GET /servlet/default.jsp HTTP/1.1 Accept : text/plain ; text/html Accept-Language : en-gb Connection : Keep-Alive HOST : localhost User-Agent : Mozilla/4.0(Compatible; MSIE 4.01; windows 98) Content-Length : 33 LastName=Saurabh&FirstName=Atul
  • 18. Whenever client need to send some request to the server it uses some HTTP specific method. HTTP 1.0 defines only two methods GET and POST. HTTP 1.1 defines five more. Method Description GET GET is the simplest and most used method. GET simply retrieves the data identified by the URI. HEAD This is similar to GET but it only retrieves the HTTP header and not the body.
  • 19. Method Description POST It is normally used in HTML forms. Post is used to transfer a block of data to the server in the entire body of the request OPTIONS The OPTIONS method is used to query a server about the capabilities it provides. PUT It is complementary of GET. It stores the entire body at a location specified by the URI.
  • 20. Method Description DELETE This method is used to delete a document from the server. The document is identified by the URI. TRACE It is used to trace the path of the request through firewall and multiple proxy server.
  • 21. Similar to HTTP Request , HTTP response consists of three parts: 1. Protocol Status code Description 2. Response Header 3. Entire Body Example HTTP/1.1 200 OK Server : Microsoft IIS/4.0 Date : Mon 3, jan 2007 13:34:60 IST Content-Type : text/html Content-Length : 112 <html> <head><title>Example</title></head> <body>Welcome</body></html>
  • 22. Client Machine Prepare HTTP Request port Convert response object to HTTP response Process & Prepare response Object Server Container Request Convert to object
  • 23. A servlet is a java based server side technology runs inside a container called servlet engine. Servlet interacts with client via a requestresponse model based on HTTP. For programming perspective a servlet is defined in two ways: 1. A servlet is a java class embedded with HTML code. 2. A servlet is a java class which extends javax.servlet.http.HttpServlet class.
  • 24. From the definition it is clear that a servlet is a java class. So, import javax.servlet.http.HttpServlet; public class MyServlet extends HttpServlet { }
  • 26. Receive Request Is servlet loaded no yes Is servlet current No request for long time Call destroy() yes no Call init() Call Service() Load Servlet Send Response
  • 27. JEE application requires a certain fixed directory structure so that the server can identify and locate resources in the app. Some names are reserved and must not use elsewhere. Some of the directories are mandatory and some are optional. Here is the structure: Root(M) Reserved(M) Reserved(M) Important(M) Required for specific purpose(O)
  • 28. 1. The Root :- The name of root directory is NOT reserved. It depends upon the project name possibly. 2. WEB-INF : - Its name is reserved and must be located inside the root directory. It is a private directory. 3. WEB-INF/classes : It contains all the java classes. 4. WEB-INF/web.xml : It is called deployment descriptor. 5. WEB-INF/lib : It contains all the external libraries possibly in form of JAR. 6. META-INF : It is optional. But it name is reserved. It contains project related configuration file. All the JSPs, HTML, JS, CSS etc go inside root directory.
  • 29. The following are the steps required to run a servlet. Step -1 : Write a Servlet import javax.servlet.http.*; import java.io.*; import javax.servlet.*; public class MyServlet extends HttpServlet { protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out=response.getWriter(); out.println(“Hello World!!!”); } }
  • 30. Step -2 : Compile The Servlet set CLASSPATH=%CATALINA_HOME%commonlibservlet.j ar;. javac MyServlet.java OR javac classpath %CATALINA_HOME%commonlibservlet.jar MyServlet.java Here CATALINA_HOME represents the installation directory of Apache Tomcat.
  • 31. Step -3 : Create the directory structure for the project. The root folder may have name Test. Step -4 : Put the servlet class in the WEB-INFclasses directory. Step -5 : Create the deployment descriptor i.e. web.xml and put the following content in this file….
  • 32. <!DOCTYPE web-app PUBLIC “-//Sun Microsystem,Inc.// DTD Web Application 2.3//EN” http://java.sun.com/dtd/web-app_2_3.dtd> <web-app> <servlet> <servlet-name>Sample</servlet-name> <servlet-class>MyServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>Sample</servlet-name> <url-mapping> /Sample</url-mapping> </servlet-mapping> </web-app>
  • 33. Step -6 : put the web.xml inside WEB-INF folder. Step -7 : put the whole directory structure inside %CATALINA_HOME%web-apps Step -8 : Run the apache server using %CATALINA_HOMEbinstartup.bat Step -9: Call the servlet from the browser http://localhost:8080/Test/Sample
  • 35. HttpServlet class gets Life-cycle method from GenericServlet class and GenericServlet provides implementation of all method present inside Servlet interface. Here are the methods defined in Servlet interface • public void init(ServletConfig config) throws ServletException • public void service ( ServletRequest request, ServletResponse response) throws IOException, ServletException • public void destroy() • public String getServletInfo() • public ServletConfig getServletConfig()
  • 36. The HttpServlet is basically used to handle HTTP Request. So HttpServlet defines some of the methods related to HTTP. Here are some of those methods…. 1. protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException 2. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException 3. protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
  • 37. When a HTTP client sends a request using any HTTP method (GET, POST, DELETE…) then the servlet engine calls corresponding doXXX method. As for example when the client sends a request using DELETE HTTP method then servlet engine call doDelete method. Notice that all doXXX methods are very similar to service method. Here are the steps in handling request using servlet…. 1. The server get a request from the client. 2. The server converts the HTTP request into ServertRequest and handed over to the container. 3. The container invoke the servlet mapped by the URI. 4. The container create a thread for each client and the thread calls the service method. The ServletRequest object is handed over to the service method. 5. The service method in turns downcast the ServletRequest into HttpServletRequest and calls the doXXX method.
  • 38. Whenever client need to send some useful information to the server then the message is sent in form of Key=value format. As form example firstname=rahul Here firstname is the key and rahul is the value. If there are many messages then each one is seperated by &. As for example firstname=rahul & lastname=dutta The HttpServletRequest parameter to the doXXX method represents the request sent by the client. This interface provides useful methods to fetch all the parameters sent by the client.
  • 39. Here are the methods provided by the HttpServletRequest interface. Sl. No Method Signature Description 1. String getParameter(String key) Returns the value associated with the key. Useful when one key is associated with one value only. E.g. fetching the value submitted through the textfield, Dropdown box etc in HTML. 2. String [] getParameterValues(String key) Returns the array of values associated with the key. Useful when one key is associated with multiple values. E.g. fetching values from HTML checkbox.
  • 40. Sl. No Method Signature Description 3. Enumeration getParameterNames() Returns all the keys sent by the client. This method can be used in conjunction with getParameter or getParameterValues. 4. RequestDispatcher getRequestDispatcher(String pageName) Returns RequestDispatcher object to either include the page referred by pageName in the current page or forward to page.
  • 41. Sl. No Method Signature Description 5. String getMethod() Return the HTTP i.e. GET, POST etc. method using that this request is sent. 6. String getRequestURI() Returns the URI associated with this request.
  • 42. Sl. No Method Signature Description 7. String getHeader(String hname) Return the value of the header represented by hname. 8. Enumeration getHeaderNames() Returns the names of all the headers sent by the client
  • 43. Sl. No Method Signature Description 7. InputStream getInputStream() Return the inputstream object if the request contains some binary data. 8. HttpSession getSession() HttpSession getSession(boolean create) Returns the session object associated with the current request.
  • 44. import javax.servlet.*; import javax.servlet.http.*; 2 import java.io.*; public class CheckBoxHandler extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { PrintWriter out=response.getWriter(); String choices[] = request.getParameterValues(“myChoice”); out.println(“You have selected…<br>”); for(int i=0; i< choices.length;i++) { out.println(“ “+choices[i]+”<br>”); } } }
  • 45. Compile the servlet… Put it at correct place inside the directory structure. Map it inside web.xml and then create an HTML form <body> <form method=“POST” actoin=“chkboxhndlr”> 3 <lable>Cricket</label><input type=“checkbox” value=“cricket” name=“myChoice”/> <lable>Basket Boll</label><input type=“checkbox” value=“basketboll” name=“myChoice”/> <lable>Hockey</label><input type=“checkbox” value=“hockey” name=“myChoice”/> <button type=“submit”>Submit</button> </form> </body>
  • 46. The mapping in web.xml <?xml version="1.0" encoding="UTF-8"?> <web-app … > 1 2 <servlet> <servlet-name>setServlet</servlet-name> <servlet-class> CheckBoxHandler </servlet-class> </servlet> 1 <servlet-mapping> <servlet-name>setServlet</servlet-name> <url-pattern>/ chkboxhndlr </url-pattern> </servlet-mapping> </web-app> 3
  • 47. Sometimes it is required to initialize the servlet with some parameters so that when the servlet is up and running the parameters are available to it. This is generally called the configuration of the servlet and is limited to one servlet in context. The servlet is configured in web.xml i.e. Deployment Descriptor using <init-param> tag. Here is the code snippet : <servlet> <servlet-name>abc</servlet-name> <servlet-class>org.MyServlet</servlet-name> <init-param> <param-name>Nname</param-name> <param-value>Atul</param-value> </init-param> </servlet> A
  • 48. The initialization parameters are available to the servlet via ServletConfig object. The GenericServlet override all the abstract method of Servlet interface. And HttpServlet class extends GenericServlet class. So the ServletConfig object can be obtained using getServletConfig() method. One can use getInitParameter(…) method to obtain the initial configuration values. Here is the code snippet. The servlet is configured in web.xml i.e. Deployment Descriptor using <init-param> tag. Here is the code snippit : protected void doGet(…… req, …..res) …. { ServletConfig g=getServletConfig(); String nName=g.getInitParameter(“Nname”); ……… } A
  • 49. Here are the methods defined ServletConfig interface Sl. No. Method Description 1. String getInitParameter(String key) Returns the values associated with key 2. Enumeration getInitParameterNames() Returns all the keys defined for the configuration of this servlet 3. ServletContext getServletContext() Returns the context object for this servlet
  • 50. The context represents the run time environment in which the servlet is running. The context is represented by the ServletContext object. Sometimes we need the set the configuration of all servlet running in an environment. That means the configuration is not limited to one particular servlet but available to all. In that case we need to talk to runtime environment and ServletContext will help. The initial configuration is also set in web.xml. Here is the way: <web-app> <context-param> B <param-name>forAll</param-name> <param-value>Good Morning</param-value> </context-param> …… </web-app>
  • 51. Note that the <init-param> is not written inside any <servlet> tag. Here is the way to obtain the initial parameter protected ……… void doGet(…… req, …….res) { ServletConfig g=getServletConfig(); ServletContext c=g.getServletContext(); String msg=c.getInitParameter(“forAll”); ……………….. } B
  • 52. Here are some of the useful methods defined in ServletContext interface. Sl. No Method Description 1. String getInitParameter(String key) Returns the initial parameters associated with the key set for the servlets. 2. Enumeration getInitParameterNames() Returns keys for all initial parameters set for the servlet. 3. RequestDispatcher getNamedDispatcher(String pageName) Returns the RequestDispatcher object for moving or including the page identified by pageName
  • 53. Sl. No Method Description 4. void setAttribute(String attribName,Object attrib) Set the attribute to the session 5. Object getAttribute(String attribName) Returns the attribute associated with the attribName. 6. RequestDispatcher getRequestDispatcher(String pageName) Returns the RequestDispatcher object for moving or including the page identified by pageName
  • 54. HTTP is a stateless protocol. That means the server is not going to maintain any state of the client and every request from the client is considered as the fresh request. But in some situation like Book Shopping it is necessary to maintain the state of the client because a client may add some book to its own cart. The state of client is loosely called its session. More precisely a session is defined as “A session is an uninterrupted request-response series between a client and the server”. The uninterrupted does not mean that client need to send the request immediately after it gets the response. Of course there might be a relaxation of time. But the server expect that client must communicate with it within the time limit.
  • 55. Mainly in E-app programmer use two technique to maintain the session. i) Cookie ii) HttpSession The Cookie The cookie is a small text file in which the server keeps some information related to the client session and store on the client local hard disk. Here are the steps when session is managed by cookie. 1) The server prepare a cookie at some point of time and add it to the response. That means when the client browser get some response it also get the cookie. The browser store the cookie at its local hard disk. Normally the server stores time span, date of creation etc. information in the cookie.
  • 56. Here is piece of code…… protected void doGet(…. Req, …. Res ) ……. { Cookie c=new Cookie(“MyCookie”,”Add Cart”); Res.addCookie(c); } 2) Next time when the browser sends a request to the server, it also sends the cookie to the server. Now it’s the duty of the server to get cookie from the request and perform some analysis task (possibly).
  • 57. protected void doGet(…. Req, …. Res ) ……. { Cookies [] c=Req.getCookies(); for(int i=0;i<c.length;i++) { Cookie c1=c[i]; String value=c1.getValue(); } }
  • 58. Here are some useful method in cookie class. Sl. No Method Description 1. void setMaxAge(int exp) Set age for cookie in seconds 2. void setValue(String value) Set the value in cookie 3. int getMaxAge() Return the life span of the cookie in seconds 4. String getValue() Returns the value set in the cookie.
  • 59. • The cookie is always stored at client side. That is why the resources at server side is saved. • Cookie is a small textual information which requires less bandwidth to travel back and forth. • It is always a chance that client may change the data written inside the cookie. So not reliable. • If the Cookie is deleted, by accident also, the session will be invalidated by the server.
  • 60. Cookie saves the server resources but gives a strong chance to the client to control the session. This disadvantage make the cookie impractical to maintain cookie. Java provides one more mechanism to maintain client session. And the mechanism is HttpSession. HttpSession does not allow the client to control the session. The server has full control over the client’s session. Whenever client need to session start, the sever generate a unique id called session id. This session id is sent back to the client. Whenever the client send request to the server it also sends it own session id. The server then verify the session id against its own repository. If the id is valid and not invalidated the server provides the allocated resource to the client.
  • 61. HttpSession is an interface in javax.servlet.http package. When the client first interact with the server it does not have the session id. The server tries to fetch the session id from the request. If the id is NOT available then the server will create a session object and generate the session id. And that is why the HttpServletRequest interface provides two method to retrieve and create the session. Sl. No. Method Name Description 1. HttpSession getSession() Always create a new session object. It does not check whether session id is present or not 2. HttpSession getSession(boolean create) If the create is true then a new session object is created. Otherwise the session object is retrieved from the request.
  • 62. Here is the code snippet to show how to create a session. protected void doGet(…… request, ….. response) throws …. { // If this is the first request for maintaining the sesion. HttpSession s=request.getSession(); // A session object is created and id is generated. . . . }
  • 63. Here is the code snippet to show how to create a session. protected void doGet(…… response) throws …. request, ….. { // for subsequent request from client HttpSession s=request.getSession(false); // An old session is fetched from the request. . . . }
  • 64. The HttpSession interface provides some important methods. Sl. No. Method Name Description 1. void setAttribute(String key, Object value) Set any java object in the session object. This java object will remain in the session until either session is invalidated or server explicitly call removeAttribute 2. Object getAttribute(String key) Returns the java object set in the session with key.
  • 65. Sl. No. Method Name Description 3. void removeAttribute(String key) Remove the object associated with key from the session object. 4. void setMaxInactiveInterval(int age) This method set the maximum time span in seconds for which the client may remain inactive. If the time span laspe the session object is destroyed. 5. void invalidate() Forcefully destroy the session.
  • 66. JEE framework two ways to set the inactive age for the session object. 1. Using the setMaxInactiveInterval(int age) method of HttpSession interface. Example : protected void doGet(……. req, ……. resp) throws …. { HttpSession hs = req.getSession(); hs.setMaxInactiveInterval(3* 60); // set the inactive age of session as 3 min. } This configuration is available to one type of session. It is possible that other client may have different setting for session object.
  • 67. 2. Using web.xml <web-app…..> <session-config> <session-timeout> 30 </session-timeout> </session-config> </web-app> Here the 30 represent 30 min and NOT 30 sec. This configuration is valid for every session object.