Namespace Request
A wrapper object for the HTTP request.
Constructor Attributes | Constructor Name and Description |
---|---|
Method Attributes | Method Name and Description |
---|---|
<static> |
Request.containsKey(name)
Determine if a certain key exists in the Request
|
<static> |
Request.forward(path)
Forward the current request to the specified resource.
|
<static> |
Request.getAttribute(name)
Retrieve an attribute from the Request, keeping it in the Request, or return null if there is no such value
|
<static> |
Request.getAttributeNames()
Retrieve a listing of the available key names in the Request
|
<static> |
Request.getContextPath()
Returns the portion of the request URI that indicates the context of the request.
|
<static> |
Request.getCookie(name)
Returns an Object containing all the usable values from the cookie, include 'value','maxAge','domain', & 'path'
|
<static> |
Request.getHeader(name)
Returns the value of the specified request header as a
String . |
<static> |
Request.getHeaderNames()
Returns an
Array of all the header names this request contains. |
<static> |
Request.getHeaders(name)
Returns all the values of the specified request header as an
Array of String objects. |
<static> |
Request.getMethod()
Returns the name of the HTTP method with which this request was made, for example,
GET, POST, or PUT.
|
<static> |
Request.getParameter(name)
Retrieves the value of the specified parameter from the URL.
|
<static> |
Request.getParameterList()
Returns an array of objects containing the names and values of each parameter submitted to the running script.
|
<static> |
Request.getParameterMap()
Returns a map of the parameters of this request.
|
<static> |
Request.getParameterNames()
Get a list of all the HTTP GET and POST parameters concatenated into a single Java array.
|
<static> |
Request.getParameterValues(name)
Returns an
Array of String objects containing all of the values the
given request parameter has, or null if the parameter does not exist. |
<static> |
Request.getProtocol()
Returns the name and version of the protocol the request uses in the
form protocol/majorVersion.minorVersion, for example, HTTP/1.1.
|
<static> |
Request.getQueryString()
Returns the query string that is contained in the request URL after the
path.
|
<static> |
Request.getRemoteHost()
Returns the fully qualified name of the client that sent the request.
|
<static> |
Request.getServerPort()
Get the port on the server through which the request was made, for instance on a simple
server setup, for a regular HTTP request, this will return 80.
|
<static> |
Request.getServletPath()
Returns the part of this request's URL that calls the servlet.
|
<static> |
Request.getTarget()
Get the absolute path to the web application root of the target of
the rewritten URL.
|
<static> |
Request.getURI()
Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.
|
<static> |
Request.getURL()
Reconstructs the URL the client used to make the request.
|
<static> |
Request.hasParameter(name)
Check to see if the specified parameter has been passed.
|
<static> |
Request.removeAttribute(key)
Remove an attribute from the Request, and return the value, or null if there is no such value
|
<static> |
Request.setAttribute(key, value)
Add an attribute to the Request
|
Method Detail
<static>
Request.containsKey(name)
Determine if a certain key exists in the Request
- Parameters:
- {String} name
- The name of the attribute
<static>
Request.forward(path)
Forward the current request to the specified resource.
<? if (validData()) { Request.forward('saveData.sjs'); } ?>
- Parameters:
- {String} path
- The path of the resource to forward to.
<static>
Request.getAttribute(name)
Retrieve an attribute from the Request, keeping it in the Request, or return null if there is no such value
- Parameters:
- {String} name
- The name of the attribute
<static>
Request.getAttributeNames()
Retrieve a listing of the available key names in the Request
<static>
{String}
Request.getContextPath()
Returns the portion of the request URI that indicates the context of the request.
The context path always comes first in a request URI. The path starts
with a "/" character but does not end with a "/" character.
- Returns:
- A
String
specifying the portion of the request URI that indicates the context of the request.
- See:
- Java Servlet API
<static>
{Object}
Request.getCookie(name)
Returns an Object containing all the usable values from the cookie, include 'value','maxAge','domain', & 'path'
<? var cookie=Request.getCookie('myCookie'); var value=cookie.value || 'defaultVal'; ?>
- Parameters:
- {String} name
- The name of the cookie to retrieve
- Returns:
- An
Object
containing at least {value:'myval',maxAge:'0',domain:'domain.com',path:'/'}
<static>
{String}
Request.getHeader(name)
Returns the value of the specified request header as a
String
.
If the request did not include a header of the specified name, this method returns null
.
The header name is case insensitive. You can use this method with any request header.
- Parameters:
- {String} name
- The name of the requested attribute
- Returns:
- a
String
containing the value of the requested header, ornull
if the request does not have a header of that name
- See:
- Java Servlet API
<static>
{Array}
Request.getHeaderNames()
Returns an
Array
of all the header names this request contains.
If the request has no headers, this function returns an empty array.
- Returns:
- An
Array
of all the header names sent with this request; if the request has no headers, an empty array
- See:
- Java Servlet API
<static>
{Array}
Request.getHeaders(name)
Returns all the values of the specified request header as an
Array
of String
objects.
Some headers, such as Accept-Language
can be sent by clients as several headers each with a different value rather than sending the header as a comma separated list.
If the request did not include any headers of the specified name, this method returns an empty Array
.
The header name is case insensitive. You can use this method with any request header.
- Parameters:
- {String} name
- The header name
- Returns:
- An
Array
containing the values of the requested header. If the request does not have any headers of that name the array will be empty
- See:
- Java Servlet API
<static>
{String}
Request.getMethod()
Returns the name of the HTTP method with which this request was made, for example,
GET, POST, or PUT. Same as the value of the CGI variable REQUEST_METHOD.
- Returns:
- A
String
specifying the name of the method with which this request was made.
- See:
- Java Servlet API
<static>
{String or Object}
Request.getParameter(name)
Retrieves the value of the specified parameter from the URL.
Note: salsa.getParameter
once returned a Boolean
"false"
object with a length
of 0. This behavior is deprecated in
the Request object, and will now return null
.
<? var param = salsa.getParameter('foo'); if (param) { print(param); } else { print('could not find parameter foo'); } ?>
<? var param = salsa.getParameter('foo') || 'bar'; // param now contains the value of the parameter, or 'bar' if it does not exist. ?>
- Parameters:
- {String} name
- The name of the parameter to retrieve.
- Returns:
- If the parameter exists, a
String
containing the specified parameter's value (including the empty string), otherwisenull
.
- See:
- Java Servlet API
<static>
{Array}
Request.getParameterList()
Returns an array of objects containing the names and values of each parameter submitted to the running script.
Parameters with more than one value will appear multiple times in the array.
- Returns:
- An array of objects with the following properties:
name
value
<static>
{Object}
Request.getParameterMap()
Returns a map of the parameters of this request. Request parameters are extra information sent with the request.
For HTTP servlets, parameters are contained in the query string or posted form data.
- Returns:
- "an immutable java.util.Map containing parameter names as keys and parameter values as map values. The keys in the parameter map are of type String. The values in the parameter map are of type String array."
- See:
- Java Servlet API
<static>
{Array}
Request.getParameterNames()
Get a list of all the HTTP GET and POST parameters concatenated into a single Java array.
for each (parameter in Request.getParameterNames()) { print(parameter + ','); }
- Returns:
- An
Array
ofString
objects that can be iterated over.
<static>
{Array}
Request.getParameterValues(name)
Returns an
Array
of String
objects containing all of the values the
given request parameter has, or null if the parameter does not exist.
<? Request.getParameterValues('array_object[]'); ?>
- Parameters:
- {String} name
- The name of the parameter to retrieve
- Returns:
- An
Array
ofString
objects containing all of the values the given request parameter has, ornull
if the parameter does not exist. If the parameter has a single value, theArray
has a length of 1.
- See:
- Java Servlet API
<static>
{String}
Request.getProtocol()
Returns the name and version of the protocol the request uses in the
form protocol/majorVersion.minorVersion, for example, HTTP/1.1.
- Returns:
- A
String
containing the protocol name and version number.
- See:
- Java Servlet API
<static>
{String}
Request.getQueryString()
Returns the query string that is contained in the request URL after the
path. This method returns null if the URL does not have a query string.
Same as the value of the CGI variable QUERY_STRING."
- Returns:
- A
String
containing the query string or null if the URL contains no query string
- See:
- Java Servlet API
<static>
{String}
Request.getRemoteHost()
Returns the fully qualified name of the client that sent the request. If the engine cannot or chooses not to resolve the hostname (to improve performance),
this method returns the dotted-string form of the IP address. For HTTP servlets, same as the value of the CGI variable REMOTE_HOST.
- Returns:
- A
String
containing the fully qualified name of the client.
- See:
- Java Servlet API
<static>
{Integer}
Request.getServerPort()
Get the port on the server through which the request was made, for instance on a simple
server setup, for a regular HTTP request, this will return 80. You may find that on the Salsa servers
the port numbers do not make much sense. This is a side effect of the way our hardware infrastructure
distributes load to maximize throughput.
- Returns:
- The port number.
<static>
{String}
Request.getServletPath()
Returns the part of this request's URL that calls the servlet. This includes either
the servlet name or a path to the servlet, but does not include any extra path
information or a query string. Same as the value of the CGI variable SCRIPT_NAME.
- Returns:
- The name or path of the servlet being called, as specified in the request URL.
<static>
{String}
Request.getTarget()
Get the absolute path to the web application root of the target of
the rewritten URL.
Almost all URLs in Salsa are rewritten to a different directory than the one in the URL. This method will return the actual location of the current script in the directory structure.
<p><?= Request.getTarget() ?></p> <p><?= Request.getURL() ?></p> // Outputs: // /packages/d/myaccount/hq/test.sjs // http://sandbox.salsalabs.com/salsa/hq/p/d/myaccount/hq/test.sjs
- Returns:
- The path and filename of the currently executing script in the web application directory, or the request URL if it has not been rewritten.
<static>
{String}
Request.getURI()
Returns the part of this request's URL from the protocol name up to the query string in the first line of the HTTP request.
The web container does not decode this String. For example:
First line of HTTP request | Returned Value |
---|---|
POST /some/path.html HTTP/1.1 |
/some/path.html |
GET http://foo.bar/a.html HTTP/1.0 |
/a.html |
HEAD /xyz?a=b HTTP/1.1 |
/xyz |
- Returns:
- The part of the URL from the protocol name up to the query string
- See:
- Java Servlet API
<static>
{String}
Request.getURL()
Reconstructs the URL the client used to make the request. The returned URL contains a protocol, server name, port number, and server path, but it does not include query string parameters.
- Returns:
- A
String
containing the reconstructed URL
- See:
- Java Servlet API
<static>
{Boolean}
Request.hasParameter(name)
Check to see if the specified parameter has been passed.
- Parameters:
- {String} name
- The name of the specified parameter
- Returns:
true
if the specified parameter is present,false
otherwise.
<static>
Request.removeAttribute(key)
Remove an attribute from the Request, and return the value, or null if there is no such value
- Parameters:
- {String} key
- The name of the attribute to remove
<static>
Request.setAttribute(key, value)
Add an attribute to the Request
- Parameters:
- {String} key
- The name of the attribute to add
- {Object} value
- The object to store in the Request. Note: Non-String Request objects will be serialized prior to storage with toJSON(). Therefore, any prototype methods on objects that are saved, or methods that cannot be iterated over must be applied after retrieving the attribute from the Request with getAttribute().