







Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
function of servlet in a website.
Typology: Lecture notes
1 / 13
This page cannot be seen from the preview
Don't miss anything!








Servlet can be described in many ways, depending on the context.
As Servlet Technology uses Java, web applications made using Servlet are Secured , Scalable and Robust.
What is web application?
A web application is an application accessible from the web. A web application is composed of web components like Servlet, JSP, Filter etc. and other components such as HTML. The web components typically execute in Web Server and respond to HTTP request.
CGI technology enables the web server to call an external program and pass HTTP request information to the external program to process the request. For each request, it starts a new process.
Sir Syed University of Engineering and
Before Servlets, CGI(Common Gateway Interface) programming was used to create web applications. Here's how a CGI program works :
Sir Syed University of Engineering and
Web Terminology
Website: static vs dynamic
It is a collection of related web pages that may contain text, images, audio and video. HTTP It is the data communication protocol used to establish communication between client and server. HTTP Requests It is the request send by the computer to a web server that contains all sorts of potentially interesting information. Get vs Post It gives the difference between GET and POST request. Container It is used in java for dynamically generate the web pages on the server side. Server: Web vs Application
It is used to manage the network resources and for running the program or software that provides services. Content Type It is HTTP header that provides the description about what are you sending to the browser.
Static website
Static website is the basic type of website that is easy to create. You don't need web programming and database design to create a static website. Its web pages are coded in HTML.
The codes are fixed for each page so the information contained in the page does not change and it looks like a printed page.
Sir Syed University of Engineering and
Dynamic website
Dynamic website is a collection of dynamic web pages whose content changes dynamically. It accesses content from a database or Content Management System (CMS). Therefore, when you alter or update the content of the database, the content of the website is also altered or updated.
Dynamic website uses client-side scripting or server-side scripting, or both to generate dynamic content.
Client side scripting generates content at the client computer on the basis of user input. The web browser downloads the web page from the server and processes the code within the page to render information to the user.
In server side scripting, the software runs on the server and processing is completed in the server then plain pages are sent to the user.
Sir Syed University of Engineering and
The Basic Features of HTTP (Hyper Text Transfer Protocol):
There are three fundamental features that make the HTTP a simple and powerful protocol used for communication:
The Basic Architecture of HTTP (Hyper Text Transfer Protocol):
The below diagram represents the basic architecture of web application and depicts where HTTP stands:
Sir Syed University of Engineering and
HTTP is request/response protocol which is based on client/server based architecture. In this web browser, search engines, etc behaves as a HTTP clients, and the Web server like Servlet behaves as a server.
HTTP Requests
The request sends by the computer to a web server that contains all sorts of potentially interesting information is known as HTTP requests.
Sir Syed University of Engineering and
Get request can be bookmarked and is more efficient.
Post request cannot be bookmarked.
Session Tracking in Servlets
Session simply means a particular interval of time.
Session Tracking is a way to maintain state (data) of an user. It is also known as session management in servlet.
Http protocol is a stateless so we need to maintain state using session tracking techniques. Each time user requests to the server, server treats the request as the new request. So we need to maintain the state of an user to recognize to particular user.
HTTP is stateless that means each request is considered as the new request. It is shown in the figure given below:
Why use Session Tracking?
To recognize the user It is used to recognize the particular user.
Session Tracking Techniques
There are four techniques used in Session tracking:
Sir Syed University of Engineering and
A cookie is a small piece of information that is persisted between the multiple client requests.
A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number.
How Cookie works
By default, each request is considered as a new request. In cookies technique, we add cookie with response from the servlet. So cookie is stored in the cache of the browser. After that if request is sent by the user, cookie is added with request by default. Thus, we recognize the user as the old user.
Types of Cookie
There are 2 types of cookies in servlets.
Non-persistent cookie
It is valid for single session only. It is removed each time when user closes the browser.
Persistent cookie
It is valid for multiple session. It is not removed each time when user closes the browser. It is removed only if user logout or signout.
Sir Syed University of Engineering and
no object is bound under the name.
2
public Enumeration getAttributeNames() This method returns an Enumeration of String objects containing the names of all the objects bound to this session.
3
public long getCreationTime() This method returns the time when this session was created, measured in milliseconds since midnight January 1, 1970 GMT.
4
public String getId() This method returns a string containing the unique identifier assigned to this session.
5
public long getLastAccessedTime() This method returns the last time the client sent a request associated with this session, as the number of milliseconds since midnight January 1, 1970 GMT.
6
public int getMaxInactiveInterval() This method returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses.
public void invalidate() This method invalidates this session and unbinds any objects bound to it.
8
public boolean isNew( This method returns true if the client does not yet know about the session or if the client chooses not to join the session.
public void removeAttribute(String name) This method removes the object bound with the specified name from this session.
public void setAttribute(String name, Object value) This method binds an object to this session, using the name specified.
11
public void setMaxInactiveInterval(int interval) This method specifies the time, in seconds, between client requests before the servlet container will invalidate this session.
Sir Syed University of Engineering and