Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
1
J2EE Architecture
Session 2.2
IETE
Objectives:
What is J2EE?
Why J2EE?
J2EE Tire Architecture.
MVC Architecture.
Http Basics
Servlet
IETE
What is J2EE?
Open and standard based platform for
developing, deploying and managing.
n-tier, Web-enabled, server-centric, and componentbased enterprise applications.
IETE
Why J2EE?
We can use all the properties of Java Technology.Platform
Independence, Secure Code, Portability etc
Simplifies the complexity of a building n-tier application.
Standardizes an API between components and application
server container.
J2EE Application
framework services
Server
and
IETE
Containers
provide
the
J2EE ARCHITECTURE
Single Tier (Mainframe-based)
Dumb terminals are directly
connected to mainframe
IETE
IETE
database
SQL queries sent, raw data
returned
Presentation, Business logic
and Data Model processing logic
in client application
Client Server systems
Ex:- Unix, mainframes
IETE
IETE
IETE
IETE
IETE
MVC ARCHITECTURE
Need for MVC
J2EE designers were faced with a question of where to place the
code in a distributed environment.
Reasonable solution: To divide the code and put them closer to
their respective tier.
This approach reminds a popular, proven 20 year old application
design pattern called MVC.
MVC is a design pattern for building maintainable applications,
introduced by Xerox researchers.
IETE
MVC ARCHITECTURE(Cont.)
What is MVC?
Technique aimed to make large applications flexible/simple during
development and maintenance.
The "model" is the internal workings of the program (the algorithms), the
"view" is how the user sees the state of the model and the "controller" is
how the user changes the state or provides input.
IETE
MVC ARCHITECTURE(Cont.)
What is MVC? (Cont.)
In this pattern, application flow is mediated by a central
controller that delegates requests to an appropriate handler.
Controller is the means by which users interacts with web
application. Controller is responsible for input to the model.
Ex: A pure GUI controller accepts input from the user and
instructs the model to create a view based on that input. If an
invalid input is sent to the controller from the view, model
informs controller to direct the view that error occurred and to
tell it to try again.
IETE
MVC Example
IETE
IETE
Servers
A server is a computer that responds to requests
from a client
Typical requests: provide a web page, upload or
download a file, send email
Apache
Apache is a very popular server
66% of the web sites on the Internet use Apache
Apache is:
Full-featured and extensible
Efficient
Robust
Secure (at least, more secure than other servers)
Up to date with current standards
Open source
Free
Why use anything else?
IETE
Ports
A port is a connection between a server and a client
Ports are identified by positive integers
A port is a software notion, not a hardware notion, so there
may be very many of them
Dynamic Pages
Request service
Return dynamically
generated HTML file
<HEADER>
<BODY
</BODY>
IETE
print $result
Servlet
Client
Server
Response
IETE
Introduction request-response
model
Request-response model.
HTTP
Request
request
Server
<html>
<head>
<html>
<body>
<head>
<body>
Client
response
HTTP
HTML
IETE
HTTP Response
Form parameters.
The content ( the actual
content).
IETE
Helper
Application
Not a
problem. I
can handle
dynamic
requests.
GET.
..
GET.
..
Web
Server
Web
Container
Client
IETE
Servlet
Http request
Web
Container
Servlet
request
response
Thread
Web
Server
Client
response
<Html>
<Body>
.
</Body>
</Html>
Service()
doGet()
IETE
S2
S1
Lifecycle Management
JSP1
Multi-threading support
S3
Security
JSP Support
S4
How does the Container know which Servlet the client has
requested for?
<web-app>
<servlet>
<servlet-name>LoginServ</servlet-nam
<servlet-class>com.Login</servlet-cla
</servlet>
<servlet-mapping>
<servlet-name>LoginServ</servlet-nam
<url-pattern>/Logon</url-pattern>
</servlet-mapping>
..
..
</web-app>
IETE
Web.xml
Servlet Lifecycle
constructor()
destroy()
init()
Initialized
Service()
IETE
Abstract class
Servlet
GenericServlet
Abstract class
HttpServlet
Concrete class
Your Servlet
IETE
IETE
http://java.sun.com/products/servlet/2.1/servlet-2.1.pdf
IETE
http://java.sun.com/products/servlet/2.1/servlet-2.1.pdf
The container
calls the init()
before the servlet
can service any
client requests.
To initialize your
servlet before
handling any
client requests.
service()
When a new
request for that
servlet comes in.
To determine
which HTTP
No. Very unlikely
method should be
called.
doGet() or
doPost()
The service()
To handle the
method invokes it business logic.
based on the HTTP
method from the
request.
init()
IETE
Do you override
it
Possibly
Always
POST (doPost())
Parameter
passing
Size
Idempotency
GET is Idempotent
Usage
HTTP Request
IETE
No
No
Yes
Yes
Send resource
Send Redirect
Request Dispatcher
IETE
Error page
Servlet 1
Servlet Config
Servlet 3
Servlet 2
Servlet Config
Servlet Config
IETE
JSP 1
Servlet Config
Servlet code
getServletContext()
getServletConfig()
Deployment
Descriptor
Scope
IETE
Types
Attributes
Parameters
Context
Request
Session
Context
Request
Servlet Init
We cannot set Init
parameters.
Method to set
setAttribute(String, Object)
Return type
Object
String
getAttribute(String)
getInitParameter
(String)
Method to get
IETE
Q&A
IETE