Java (current. Jakarta) Server Pages is a framework used for web application development.

This post will discuss:

  • Redirects
  • Cookies


Redirects


The response object has multiple methods for page response behavior.

Methods for cookie object:

setPath():
Assigns path for cookie on server.
setValue():
Assigns value field for cookie.
setVersion():
Assigns cookie version.
getMaxAge():
Assigns cookie lifespan.
getName():
Gets cookie name.
getPath():
Gets cookie path.
getValue():
Gets cookie value.
getVersion():
Gets cookie version.


response.sendRedirect(URL) can be assigned an absolute or relative address.




Cookies


Cookies are blocks of HTTP data that persist in the client. Cookies are made in the server and saved client-side. The server can read these cookies on the client and can modify them. They can exist locally and persist.

Cookies can be up to 4 KB in size, and are allotted 50 per domain.
The constructor for cookies is as follows:

Cookie cookie = new Cookie("abc", "123");


Cookies are added:

response.addCookie(cookie);


Cookies can be deleted after selection:

    		cookies[c].setMaxAge(0);
    		response.addCookie(cookies[c]);


A for loop may be used to select from an array of cookies, as multiple cookies may be used in a domain.


As the below diagram shows, cookies are stored locally for use by the servlet when responding to client requests. Any data (fruit in diagram) can be saved to the cookie.

The cookie object supports the following methods:

Methods for cookie object:

setPath():
Assigns path for cookie on server.
setValue():
Assigns value field for cookie.
setVersion():
Assigns cookie version.
getMaxAge():
Assigns cookie lifespan.
getName():
Gets cookie name.
getPath():
Gets cookie path.
getValue():
Gets cookie value.
getVersion():
Gets cookie version.


-gonkgonk


<
Previous Post
Java Server Pages - Request Object
>
Next Post
Java Server Pages - Session Object