Storing the information in a session variable
After gathering the information, you must store it in the session variable. The code that stores the information varies depending on your server technology and the method you use to gather the information.
If you gathered the information with an HTML form with the POST method and a menu object called optCity (as in the previous section of this article), then the following code stores the information in a session variable called location.
ASP:
<% Session("location") = Request.Form("optCity") %>
ColdFusion:
<CFSET session.location = form.optCity>
JSP:
<% session.setAttribute("location", request.getParameter("optCity")); %>
If you use a hypertext link with a URL parameter called city (or an HTML form with the GET method and a text field called city) to gather the information, then the following statements store the information in the session variable:.
ASP:
<% Session("location") = Request.QueryString("city") %>
ColdFusion:
<CFSET session.location = url.city>
JSP:
<% session.setAttribute("location", request.getParameter("city")); %>
|