A very simple random generator has been created by converting the
system time (current) into the session identifier.

sessionId = Long.toString(now);

If your application contains sensitive data, you should consider
implementing a more secure random number generator for session
identifiers.

getSessionID does not usually return a valid session
identifier. This could be the same as the session identifier passed to
the method or it could be a newly generated session identifier.

return sessionId;

getSessionID should be invoked at the beginning of
every JSP file to ensure that the page has a valid session identifier
for URL rewriting (explained in the next section) and for invoking the
setValue and getValue methods.

The setValue method

setValue is used to store a String value associated
with a String called name. This name-value pair should remind you of a
Dictionary. The setValue method also needs a valid
session identifier for its first argument. It is assumed that the
getSessionID method has been invoked before this method
is called and so a validated session identifier is certain to
exist. The session identifier passed to this method will not be
validated again.

The setValue method effectively does the
following.

If the String value is associated with a name that does not
yet exist, the new name-value pair will be appended to the text
file.

If the String value is associated with a
name that already exists, the old value is replaced by the new
value.

q

The setValue method stores the name-value pair in the
following format.

name-1 value-1
name-2 value-2
name-3 value-3
.
.
.
name-n value-n

Like any other Java applications, name is case-sensitive.

The setValue method has the following signature.

public void setValue(String sessionId, String name, String value)

It first tries to find the corresponding session text file. If the
file does not exist, the method will return without doing anything. If
the session text file is found, the method will read every line of the
text file and compare the line with name. If the line begins with
name followed by a white space, it means the name already
exists and the value is replaced. If the comparison does not result in
a match, the line will simply be copied to the temporary file.