Example of values retrieved from session variables
Continuing the example from a previous section
(see Example of information stored
in session variables), you're working on a site with a large audience
of senior citizens. Your start page has two links to record the user's
text preference. One link promises larger, easy-to-read text throughout
the site, and the other will produce regular-size text. When clicked,
a session variable called font_pref is created on the server that holds
one of two values: large or small.
Now you want to retrieve the user's preference from the session variable and use it to set the font size in the CSS styles of each page. To do so, you add the following code to each page in your site.
ASP
<style type="text/css">
p {font-size: <%=Session("font_pref")%>}
h3 {font-size: <%=Session("font_pref")%>}
</style>
ColdFusion
<style type="text/css">
<CFOUTPUT>
p {font-size: #session.font_pref#}
h3 {font-size: #session.font_pref#}
</CFOUTPUT>
</style>
JSP
<style type="text/css">
p {font-size: <%=session.getAttribute("font_pref")%>}
h3 {font-size: <%=session.getAttribute("font_pref")%>}
</style>
If you click "Normal Text" on the start page, the text on the following page will be normal size:
If you view the source code for this page in the browser (for example, by choosing View > Source in Microsoft Internet Explorer), you'll see the following lines:
<style type="text/css">
p {}
h3 {}
</style>
The server retrieved the value "small" from the user's session variable and inserted it in the CSS styles above.
If you click "Larger Text" on the start page, the text on the following page will appear larger than normal:
If you view the source code for this page in the browser, you'll see the following lines:
<style type="text/css">
p {}
h3 {}
</style>
The server retrieved the value "large" from the user's session variable and inserted it in the CSS styles above, making text in <p> and <h3> tags appear larger than normal in the browser.
|