You are on page 1of 4

Servlet Framework

1. Web Servers
1.1. Web Application versus Standalone Application

Standalone Application Web Application

Interaction: how does the user interact with App


Through user interface: - Implemented using different
- Base on customer requirements. languages (PHP, JSP, ASP,…) but
- Implemented using libs that are based on HTML
different ex: java -swing, C- - User make request by using a
ncursors, ... browser

Distribution or Dependency
- A single package includes libs one - A single package includes libs
executable to run it - Web container and web server are
needed to run App: Jetty, IIS,
Apache, Tomcat, Websphere

Implementation
Provide 1 method static void main Java  provide many servlets

1.2. HTTP and Web Containers


1 web server  1 web container  many Web apps

1.2.1. Responsibilities

Web Server Web Container


- Listens for requests: open a port - Provides support for servlets (Java
(80 or 8888) API)
- Dispatches or forwards requests to + Reading web.xml
other components or applications + Creating container
- Serves content: Images, CSS, + Providing context
Javascript, HTML files + Wrap request/response
- Implement HTTP( Hyper Text - Controls life cycle of servlets
Transport Protocol) + Start
+ Shut down
Jetty Example
- Connection listener App context
+ HTTP  open port 8888 - Alarmpoint
+ AJP  open port 8889 + URL /alarmpoint
+ SSL  open port 443 + Session management
- Resource handler: serving static + Cookies
content + Time out
- Thread pool: control threads to - WebService
make faster + URL  /api
+ Worker threads: 250 + Session management
- Mobile gateway
+ URL  /mg
+ Session management

1.3. Servlet Framework


1.3.1. web.xml: each web app provide web.xml file for context
configuration:
Jetty
- Static resource
- Alarmpoint
+ web.xml, Cocoon
- WebServices
+ web.xml, Axis2
- Mobile Gateway
+ web.xml, JSP
1.3.2. URL Flow Diagram
Request

Is static URL
/ (root)

/alarmpoint Cocoon

/api Axis2 Send response

/mg JspServlet

1.4. Session Management


1.4.1. What is a session?
- Unique identifier/ attribute
- Provided as part f the servlet framework
- May be used by a web app (Ext: AP webservice not use a
session)
- Most commonly used to identify a user session
- Managed by the web container:
+ Creation
+ Configuration: timeout/removal
- There are two methods for session tracking: cookies and url
rewriting. If use cookies, we don't have to care about session
tracking.
1.4.2. URL Encoding: url rewriting
- Encoding URL will add sessionId into URL by using function
httpResponse.encodeURL(….)
- Config EncodeURLTransformer in sitemap file: determine what
will be included and excluded. Important functions:
startElement(…) and encodeURL(…)
User Webserver
Request login

Response to home page


1.4.3. Cookies with a SesionID
- Only support when both client and server use cookie.
- If Cookies is used, sessionID will be removed from url and it
will be saved in cookie.
- In login page, there is a check box. And when we click on this,
it means that we will use the cookie in server side.
- Configuration: assets/context/alarmpoint.xml

1.4.4. Client/Server Sequence Diagram

Question 1: how about encode-url and use-cookies config in dev.build.properties


file? Where and when are they used?
<webui>

<deploy>true</deploy>
<encode-url>true</encode-url>
<use-cookies>false</use-cookies>
</webui>

You might also like