Accessibility
 
Home > Products > UltraDev > Support > Defining Dynamic Content
Dreamweaver UltraDev Icon Macromedia Dreamweaver UltraDev Support Center - Defining Dynamic Content
Retrieving URL parameters with server-side scripts

After you pass URL parameters to the server, you must retrieve them from server memory to use them in your web application. The quickest way to retrieve URL parameters from memory is to write a small server-side script.

Here are the ASP, ColdFusion, and JSP expressions that retrieve URL parameters.

ASP (VBScript and JavaScript)

Request.QueryString("paramName")

ColdFusion

url.paramName

JSP

request.getParameter("paramName")

You can assign the parameter to a local variable, a global variable, or even a session variable. For example, if the URL parameter is called action, then the following expressions assign the parameter's value to the string variable myVar.

ASP/VBScript

<% 
Dim myVar
myVar=Request.QueryString("action")
%>

ASP/JavaScript

<% var myVar=Request.QueryString("action") %>

ColdFusion

<cfset myVar=url.action>

JSP

<% String myVar=request.getParameter("action") %>

For information on assigning parameters to session variables, see Using session variables in your web applications.

You can also place the parameter's value directly in your HTML code. For example, suppose you want to ask the user to choose the background image for a JSP page about an air show. First, you create a URL parameter called fileName on a welcome page to pass the path and name of the image file to the airshow.jsp page on the server. You use links to create the URL parameter, as shown in the following example:

<a href="airshow.jsp?fileName=images/jet_learjet60.jpg">
    Learjet wallpaper</a><br>
<a href="airshow.jsp?fileName=images/jet_challenger.jpg">
    Challenger wallpaper</a>

Next, you insert the parameter's value directly into the HTML body tag of the airshow.jsp page as shown in the following example:

<body background=<%=request.getParameter("fileName")%>>

When you click the "Learjet wallpaper" link on the welcome page, the server replaces the JSP scriptlet on the airshow.jsp page with the value of the URL parameter. The following body tag appears in the source code for the airshow.jsp page in the browser:

<body background=images/jet_learjet60.jpg>

To Table of Contents Back to Previous document Forward to next document