Storing information in session variables
Once you gather and send information to the server, you can store the information in session variables by adding a few lines of code to the page specified on the page used to gather the information. The "destination" page is specified in either the ACTION attribute of the HTML form or the HREF attribute of the hypertext link on the starting page.
The code for storing the information in a session variable varies depending on your server technology and the method you use to gather the information. Here's the basic syntax for each server technology.
ASP
<% Session(" variable_name ") = value %>
ColdFusion
<CFSET session. variable_name = value>
JSP
<% session.setAttribute("variable_name", value); %>
The value expression is usually a server expression like Request.Form("lastname") . For example, if you use a URL parameter called product (or an HTML form with the GET method and a text field called product) to gather the information, then the following statements store the information in a session variable called prodID.
ASP
<% Session("prodID") = Request.QueryString("product") %>
ColdFusion
<CFSET session.prodID = url.product>
JSP
<% session.setAttribute("prodID", request.getParameter("product")); %>
If you use an HTML form with the POST method and a text field called txtProduct to gather the information, then the following statements store the information in the session variable.
ASP
<% Session("prodID") = Request.Form("txtProduct") %>
ColdFusion
<CFSET session.prodID = form.txtProduct>
JSP
<% session.setAttribute("prodID", request.getParameter("txtProduct")); %>
|