You are on page 1of 6

2.

Methods of RequestDispatcher interface


response)throws
public vold forward(ServletRequest request, ServletResponse
ServletException, java.io.IOException:

Forwards arequest from aservlet to another resource (servlet, JSP file, or HTML fle) on the servery
response)throws
public void include(ServletRequest request,ServletResponse
ServletExXception, java.io.IOException:
Includes the content of a resource (servlet, JSP page, or HTML file) in the response/

67

Scanned with CamScanner

RequestDispatcher
Unit lI-Chapter 1

tareardmhed

incudellmethed
Seretl

Sen

getet
Fint
Some of the common usage of cookies are:

1. Session authentication use Cookies


2. Personalized response to the client based on their preference, for example we can set
background color as cookiein client browser and then use it to customize response
background color, image etc.
3) Request +Cookie

) Request

2) Response + Cookie

Browser
Server
L4 Serviet Cookies Methods
public void setDomain(String pattern)

This method sets the domain to which cookie applies, for example google.com.
public String getDomain()
" This method gets the domain to which cookie applies, for example google.com.
public void setMaxAge(int expiry)
expires.
This method sets how much time (in seconds) should elapse before the cookie

public int getMaxAge(0


cookie, specified in seconds, By default, -1
This method returns the maximum age of the
shutdown.
indicating the cookie will persist until browser

74

Scanned with CamScanner

Cookies
Unit ll- Chapter 2

public String getName()


after
cookie. The name cannot be changed
This method returns the name of the
creation.
newvalue)
public void setValue(String
associated with the cookie
This method sets the value
public String getValuel)
associaed with the cookie.
.This method gets the value
public vold setPath(String uri)
cookie applies.
. This method sets the path to which this

public String getPath()


applies.
This method gets the path to which this cookie

public void setSecurelboolean flag)


should only be sent
This method sets the boolean value indicating whether the cookie
over encrypted (i.e. SSL) connections.

public void setComment(String purpose)


.This method specifies a comment that describes a cookie's purpose. The comment i

useful if the browser presents the cookie to the user.


public String getComment()
This method returns the comment describing the purpose of this cookie, or null if the
cookie has no comment.
UNIT I-CHAFPTER 3
SESSIONS
Contents:

What Are Sessions?


Lifecycle Of Http Session
Session Tracking With Servlet API
AServlet Session Example

|1. Introduction
Kession 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
.Attp protocol is a stateless so we need to maintain state using session tracking
techniques. Each time user requests the server, server treats the request as the new
request. So we need to maintain e state of an user to recognize to particular user.
HTTP 0s stateless that means each request is considered as the new request.
All requests and responses are independent. But sometimes you need to keep track of
client's activity across multiple requests( For eg. When a User logs into your website,
not matter on which web page he visits after logging in, his credentials will bewith the
server, until he logs out. So this is managed by creating asession.
" Session is used to store everything that we can get from the cli¿nt from all the requests
the client makes.
3.5 Session Management API
of the
Session Management API is built on top of above methods for session tracking. Some
major disadvantages of all the above methods are:
we have to store some data
1/ Most of the time we don't want to only track the session, requirea lot of effort if we
we can use in future requests. .This will
into the session that
try to implement this. complete in themselves, all of them won't work in a
2. All the above methods are not methods of session
solution that can utilize these
particular scenario. So we need a
cases
tracking to provide session management in all
bie trom the original ðo package.

Blocking vs. Non-blocking i0


Java IO's various streams are blocking That means, that when a thread invokes
a readjor writc that thread is blocked until there is sorpe data to
written. The thread can do nothing else in the meantime read, or the daa
aVa NIOs non-blocking mode enables athread to reguest reading data from achannel, and
only get what is currently available, or nothing at al, if no data s currently avalable. th
than remain blocked until data becomes available for readirg. the thread can go on w
something else
"Thesame is true for non-blocking witing. Athread can request that some data be writtento
a dhanne, but not walt for it to be fuly writen. The thread can then go on and do
something else in the mean time)
What threads spend their idle time on when not blocked in IO calls, is usually performing io
on other channels in the meantime. That is, a single thread can now manage multiple
channels of input and output.

You might also like