Variables

                                                                                                                                                                                                                                                                                                                                      Back to [Book]     [Topic]

Variables

The Web Server includes a set of variables predefined by the server, as well as the capability for you to define custom variables. This section includes the following:

Predefined Variables

Predefined variables are implicitly defined by the server. The following table lists the predefined variables and their descriptions:

Table A-1 Predefined Variables

Variable Description
$n Regular expression backreference (value of the _n_th capturing subpattern, n = 1...9), for example, $1. Regular expression backreferences are only available within the body of If and ElseIf containers, and only if the container expressions includes one or more regular expressions. For more information on If and ElseIf, see If, ElseIf, and Else.
$& Value that matched a regular expression. Regular expression backreferences are only available within the body of If and ElseIf containers, and only if the container expressions includes one or more regular expressions. For more information on If and ElseIf, see If, ElseIf, and Else.
$auth_group Authenticated user's group (alias for $vars{'auth-group'}).
$auth_type Authentication method (alias for $vars{'auth-type'}).
$auth_user Authenticated user name (alias for $vars{'auth-user'}).
$browser Web browser version (alias for $headers{'user-agent'} if the client sent a User-Agent header or an empty string).
$chunked Boolean variable that indicates whether request body was sent using chunked encoding.
$code Response status code.
$cookie{'name'} Value of the cookie name from request.
$dns Alias for $client{'dns'}.
$env{'name'} Value of the environment variable name (includes CGI/SHTML environment variables).
$headers{'name'} Value of name from rq->headers, that is, value of the request header name where name is a lowercase string.
$id Virtual server ID as specified by the name subelement of the virtual-server element in server.xml. For more information, see virtual-server.
$internal Boolean that indicates whether request was internally generated.
$ip Alias for $client{'ip'}.
$keep_alive Boolean that indicates whether the connection will be kept open.
$keysize Alias for $client{'keysize'}.
$method Request method (alias for $reqpb{'method'}).
$path Requested path (either URI, partial path, or file system path depending on stage).The predefined variable path is the value of path from rq->vars. If path isn't set in rq->vars (for example, if NameTrans hasn't completed), path gets the value of ppath from rq->vars.
$path_info Alias for $vars{'path-info'}.
$ppath Alias for $vars{'ppath'}.
$protocol Request protocol (alias for $reqpb{'protocol'}).
$query Request query string (alias for $reqpb{'query'}).
$reason Response reason phrase.
$referer Alias for $headers{'referer'}.
$reqpb{'name'} Value of name from rq->reqpb.
$restarted Boolean that indicates whether request has been restarted.
$secret_keysize Alias for $client{'secret-keysize'}.
$server_url Prefix for self-referencing URLs.
$time Time the request was received as the number of seconds since 00:00:00 UTC, January 1, 2006.
$time_day Day of the month when the request was received. Value can be from 01 to 31.
$time_hour Hours since midnight when the request was received. Value can be from 00 to 23.
$time_min Minutes after the hour when the request was received. Value can be from 00 to 59.
$time_mon Month of the year when the request was received. Value can be from 01 to 12.
$time_sec Seconds after the minute when the request was received. Value can be from 00 to 61.
$time_wday Day of the week when the request was received. Value can be from 0 to 6, where 0 corresponds to Sunday.
$time_year Four-digit year when the request was received.
$type Alias for $srvhdrs{'content-type'}.
$uri URI of the requested resource (alias for $reqpb{'uri'}).
$url URL of the requested resource.
$urlhost Host name to which the client connected.
$vars{'$headers{'name'} Value of name from rq->vars.
$security Boolean that indicates whether a secure transport was used.
$senthdrs Boolean that indicates whether response headers have been sent.
$srvhdrs{'$headers{'name'} Value of name from rq->srvhdrs, that is, value of response header name where name is a lowercase string.

Custom Variables

You can define custom variables in the server.xml file using the variables element. These variables can then be used in function parameters in obj.conf functions. You can also define variables at request time using the set-variables function in obj.conf.

For more information, see variable and set-variable.

Note -
Because predefined variables take precedence over custom variables, it is a best practice to use uppercase names for custom variables. Using uppercase avoids conflicts with the lowercase predefined variables, should the list of predefined variables be extended in the future.

Resolving Variables

The server uses the following order when attempting to resolve a $variable:

  1. Predefined variables
  2. Variables defined at request time using set-variable in obj.conf
  3. Variables defined by the virtual-server element's variable subelement in server.xml
  4. Variables defined by the server element's variable subelement in server.xml

When you define a $variable at request time, it is stored as a name-value pair in the rq->vars pblock. These variables are given a higher precedence than server.xml variables so that server.xml variables can be overridden at request time.

Labels

configurationfile configurationfile Delete
+configguide +configguide Delete
java java Delete
server server Delete
configuration configuration Delete
administrator's administrator's Delete
sun sun Delete
webserver webserver Delete
application application Delete
system system Delete
filereference filereference Delete
webtier webtier Delete
guide guide Delete
file file Delete
webserver70 webserver70 Delete
sunjava sunjava Delete
web web Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Sign up or Log in to add a comment or watch this page.


The individuals who post here are part of the extended Sun Microsystems community and they might not be employed or in any way formally affiliated with Sun Microsystems. The opinions expressed here are their own, are not necessarily reviewed in advance by anyone but the individual authors, and neither Sun nor any other party necessarily agrees with them.

Copyright 1994-2009 Sun Microsystems, Inc.
Powered by Atlassian Confluence
Sun Guidelines on Public Discourse Privacy Policy Terms of Use Trademarks Site Map Employment Investor Relations Contact