What data can the Request and Session objects hold?

In the case of request dispatcher – forward or include methods, the request object is transferred as well, along with all parameters that it holds.
sendRedirect, fresh doPost/ doGet result in fresh request objects, hence data contained in the request object is not universally available in the session, and in fact, is temporary to the extent of transmitting from client-to-servlet and between servlet-chains.
Hence session-tracking comes into the picture. Session-tracking internally uses cookies to implement its functioning and is alive until it times-out or is invalidated, so the data stored in a session is in fact serialized and written on the client side in the form of cookies (in small files)…
Hence session objects can hold data across multiple screens of an application that will not be lost unless the session is explicitly invalidated by the code or the browser is closed.
Another point to be considered is that the request object can only hold small string values (parameters) that are generated by the client and cannot be manipulated between servlet chains.
In contrast, sessions can be loaded with entire objects that can be modified (and accessed) by any participating servlet/ jsp of the application.

About cuppajavamattiz
Matty Jacob - Avid technical blogger with interests in J2EE, Web Application Servers, Web frameworks, Open source libraries, Relational Databases, Web Services, Source control repositories, ETL, IDE Tools and related technologies.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: