Java Reference
In-Depth Information
Variables can be simple or complex. You could, for example, create a class that
contains all the variables that need to exist across interactions between the browser
and the Web server and store an instance of the class in the session when the user
first enters the Web site. For every interaction after that, you retrieve the instance
associated with the session and use it for the logic. Since each user has a unique ses-
sion and a unique instance of the class containing your variables, you can act on all
the variables in the instance without worrying about trashing the variables associ-
ated with a different user.
If you have experience in programming CICS or IMS in an IBM environment or
similar technologies on other platforms, you may notice considerable similarity be-
tween a servlet and a mainframe TP program. In CICS, each execution of the pro-
gram is a transaction unto itself. No permanent connection exists between the user
at the terminal and the program. CICS makes use of the COMMAREA to store
data between executions, just as a servlet uses the Session object.
J AVA S ERVER P AGES
Java Server Pages (JSPs) came about with the recognition that large Web projects
often required many different types of expertise. Most Web designers are not pro-
grammers, and most programmers are not good Web designers. In addition, plac-
ing HTML code inside of Java print statements is tedious (although some packages
have been developed to simplify this), and it requires recompilation every time the
appearance of the Web page needs to change. Imagine having to recompile to
change background colors or add an icon.
A JSP typically looks more like HTML than Java, although it is possible to
embed a significant amount of Java code into the page. Following is the code for an
enhanced Welcome page you might display after a user has logged into the site and
you've stored the user ID in the Session object.
Search WWH ::




Custom Search