Class WEnvironment
- Direct Known Subclasses:
WTestEnvironment
The environment provides information on the client, and gives access to startup arguments.
Usage example:
WEnvironment env = WApplication.instance().environment();
// read an application startup argument
// (passed as argument in the URL or POST'ed to the application).
if (!env.getParameterValues("login").isEmpty()) {
String login = env.getParameterValues("login").get(0);
//...
}
// Check for JavaScript/AJAX availability before using JavaScript-only
// widgets
WTextArea textEdit;
if (!env.isAjax())
textEdit = new WTextEdit(); // provide an HTML text editor
else
textEdit = new WTextArea(); // fall-back to a plain old text area.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns whether the user agent is Chrome.booleanReturns whether the user agent is Gecko-based.booleanReturns whether the user agent is Microsoft Internet Explorer.booleanagentIsIElt(int version) Returns whether the user agent is an older version of IE.booleanReturns whether the user agent is Internet Explorer Mobile.booleanReturns whether the user agent is Mobile WebKit-based.booleanReturns whether the user agent is Opera.booleanReturns whether the user agent is Safari.booleanReturns if the user agent is a (known) indexing spider bot.booleanReturns whether the user agent is WebKit-based.Returns the accept header.getAgent()Returns the user agent type.getCgiValue(String varName) Returns a raw CGI environment variable.Returns the IP address of the client.The type of the content provided to the browser.Returns a cookie value.Returns the cookies from the environment.Returns the deployment path.doubleReturns the browser-side DPI scaling factor.getHeaderValue(String name) Returns a header value.Returns the server host name that is used by the client.Returns the initial internal path.static StringWt's JavaScript scope.static StringReturns the version of the JWt library.Returns the preferred language indicated in the request header.getParameter(String name) Returns a single value for a query parameter.Parameters passed to the application.String[]getParameterValues(String name) Returns values for a query parameter.Returns the referer.intReturns the vertical resolution of the client's screen.intReturns the horizontal resolution of the client's screen.Returns the servlet.Returns the email address of the server admin.Returns the web server signature.Returns the web server software.Returns the time zone name as reported by the client.Returns the time zone offset as reported by the client.Returns the URL scheme used for the current request ("http"or"https").Returns the user agent.booleanhasAjax()Returns whether the browser has enabled support for AJAX.booleanReturns whether the browser has enabled support for JavaScript.booleanhasWebGL()Returns whether the browser has support for WebGL.booleanReturns whether internal paths are implemented using URI fragments.booleanReturns whether the incoming request is treated like a bot.booleanisTest()Returns whether this is a mocked test environment.booleanReturns whether the request should be treated like a bot.booleanReturns whether the browser has enabled support for cookies.booleanReturns whether this agent supports CSS3 animations.
-
Field Details
-
isLikelyBotGetRequest_
protected boolean isLikelyBotGetRequest_ -
timeZoneName_
-
redirectSecret_
-
-
Method Details
-
getJavaScriptWtScope
Wt's JavaScript scope. -
getParameterMap
Parameters passed to the application.Arguments passed to the application, either in the URL for a http GET, or in both the URL and data submitted in a http POST.
- See Also:
-
getParameterValues
Returns values for a query parameter.Returns an empty list if the parameter was not defined.
One or more values may be associated with a single argument.
For example a JWt application
foo.wtstarted ashttp://.../foo.wt?hello=Hello&hello=Worldwill result in both values"Hello"and"World"to be associated with the argument"hello".- See Also:
-
getParameter
Returns a single value for a query parameter.Returns the first value for a parameter, or
nullif the parameter is not found.- See Also:
-
getCookies
Returns the cookies from the environment.This returns all cookies that were present in initial request for the application. Cookies set with
WApplication#setCookie()are not taken into consideration.Cookies allow you to persist information across sessions, but note that not all clients may support cookies or may some clients may be configured to block cookies.
-
getCookie
Returns a cookie value.Returns 0 if no value was set for the given cookie.
- See Also:
-
getHeaderValue
Returns a header value.Returns a header value, or an empty string if the header was present.
-
supportsCookies
public boolean supportsCookies()Returns whether the browser has enabled support for cookies.When the user disables cookies during the visit of the page, this value is not updated.
- See Also:
-
hasJavaScript
public boolean hasJavaScript()Returns whether the browser has enabled support for JavaScript.This is the same as
hasAjax(): JWt only considers using JavaScript when it has detected AJAX support.- See Also:
-
hasAjax
public boolean hasAjax()Returns whether the browser has enabled support for AJAX.Without support for JavaScript/AJAX, JWt will still be able to serve the application, but with one considerable limitation: only the
WTimer.timeout(),WInteractWidget.clicked(),WApplication.internalPathChanged(), andWAbstractArea.clicked()signals (and any derived signals) will generate events.Every event will cause the complete page to be rerendered.
- See Also:
-
hasWebGL
public boolean hasWebGL()Returns whether the browser has support for WebGL.Support for WebGL is required for client-side rendering of
WGLWidget. -
getScreenWidth
public int getScreenWidth()Returns the horizontal resolution of the client's screen.Returns -1 if screen width is not known.
- See Also:
-
getScreenHeight
public int getScreenHeight()Returns the vertical resolution of the client's screen.Returns -1 if screen height is not known.
- See Also:
-
getDpiScale
public double getDpiScale()Returns the browser-side DPI scaling factor.Internet Explorer scales all graphics, fonts and other elements on high-density screens to make them readable. This is controlled by the DPI setting of the display. If all goes well, you do not have to worry about this scaling factor. Unfortunately, not all elements are scaled appropriately. The scaling factor is supposed to be used only internally in JWt and is in this interface for informational purposes.
- See Also:
-
getLocale
Returns the preferred language indicated in the request header.The language is parsed from the HTTP
Accept-Languagefield, if present. If not, the locale is empty.If multiple languages are present, the one with the highest "q"uality is assumed, and if a tie is present, the first one is taken.
-
getTimeZoneOffset
Returns the time zone offset as reported by the client.This returns the time offset that the client has relative to UTC. A positive value thus means that the local time is ahead of UTC.
This requires JavaScript support.
-
getTimeZoneName
Returns the time zone name as reported by the client.Note: This requires JavaScript support and is only supported by browsers that implement the JavaScript Internationalization API. No version of Internet Explorer supports this, but modern browsers do. If not supported, this will return the empty string.
-
getHostName
Returns the server host name that is used by the client.The hostname is the unresolved host name with optional port number, which the browser used to connect to the application.
Examples:
www.mydomain.comlocalhost:8080
For HTTP 1.1 requests, this information is fetched from the HTTP
Hostheader. If JWt is configured behind a reverse proxy, then the last entry in the HTTPX-Forwarded-Hostheader field is used instead (to infer the name of the reverse proxy instead).For HTTP 1.0 requests, the HTTP
Hostheader is not required. When not present, the server host name is inferred from the configured server name, which defaults to the DNS name. -
getUrlScheme
Returns the URL scheme used for the current request ("http"or"https"). -
getUserAgent
Returns the user agent.The user agent, as reported in the HTTP
User-Agentfield.- See Also:
-
getReferer
Returns the referer.The referer, as reported in the HTTP
Refererfield. -
getAccept
Returns the accept header.The accept header, as reported in the HTTP
Acceptfield. -
agentIsSpiderBot
public boolean agentIsSpiderBot()Returns if the user agent is a (known) indexing spider bot.Note: currently the list of know bots is quite small. This method is used internally to render the web application for optimal indexing by bots:
- there is no detection for JavaScript, instead the application is directly served assuming no JavaScript support.
- session information is omitted from the Urls.
- no sessions are created (they are immediately stopped after the request has been handled).
- auto-generated
idandnameattributes are omitted from DOM nodes. In this way, the generated page is always exactly the same.
-
isLikelyBotGetRequest
public boolean isLikelyBotGetRequest()Returns whether the incoming request is treated like a bot.This can be used to check whether an incoming request is likely to originate from a bot client. The request will be treated the same way as a normal bot.
Currently, this verifies whether a newly incoming GET request carries a
wtdparameter. For a new request this should never be the case, unless this page was scraped before. The session would be expired by now, and this request should then not be valid.Note: If a user were to get here, they would be served the same page a bot would see. This does not contain anything session-related. Once they would navigate on the page, they would be granted a new session, which will be tracked for subsequent requests.
- See Also:
-
isTreatLikeBot
public boolean isTreatLikeBot()Returns whether the request should be treated like a bot.If the agent matches any of the agents configured as bots agents, or if the request is suspicious, the application will handle them as a bot.
These responses will not contain session related content, and their session will be quickly closed server-side.
- See Also:
-
getServerSignature
Returns the web server signature.The value of the CGI variable
SERVER_SIGNATURE.Example:
<address>Apache Server at localhost Port 80</address>. -
getServerSoftware
Returns the web server software.The value of the CGI variable
SERVER_SOFTWARE.Example:
"Apache" -
getServerAdmin
Returns the email address of the server admin.The value of the CGI variable
SERVER_ADMIN.Example:
"root@localhost" -
getClientAddress
Returns the IP address of the client.The (most likely) IP address of the client that is connected to this session.
This is taken to be the first public address that is given in the Client-IP header, or in the X-Forwarded-For header (in case the client is behind a proxy). If none of these headers is present, the remote socket IP address is used.
-
getInternalPath
Returns the initial internal path.This is the internal path with which the application was started.
For an application deployed at
"/stuff/app.wt", the following URL indicates an internal path"/this/there":http://www.mydomain.com/stuff/app.wt/this/there -
getDeploymentPath
Returns the deployment path.This is the path at which the application is deployed.
- See Also:
-
getLibraryVersion
Returns the version of the JWt library.Example:
"1.99.2" -
getCgiValue
Returns a raw CGI environment variable.Retrieves the value for the given CGI environment variable (like
"SSL_CLIENT_S_DN_CN"), if it is defined, otherwise an empty string. -
getContentType
The type of the content provided to the browser.This is here for backwards compatibility, but the implementation now alwasy returns HTML5.
-
getAgent
Returns the user agent type.This returns an interpretation of the
getUserAgent(). It should be used only for user-agent specific work-arounds (as a last resort). -
agentIsIE
public boolean agentIsIE()Returns whether the user agent is Microsoft Internet Explorer.- See Also:
-
agentIsIElt
public boolean agentIsIElt(int version) Returns whether the user agent is an older version of IE.Returns whether the agent is an IE version older than the given version.
- See Also:
-
agentIsIEMobile
public boolean agentIsIEMobile()Returns whether the user agent is Internet Explorer Mobile.Returns also
truewhen the agent is Internet Explorer 5 or older.- See Also:
-
agentIsOpera
public boolean agentIsOpera()Returns whether the user agent is Opera.- See Also:
-
agentIsWebKit
public boolean agentIsWebKit()Returns whether the user agent is WebKit-based.Webkit-based browsers include Safari, Chrome, Arora and Konquerer browsers.
- See Also:
-
agentIsMobileWebKit
public boolean agentIsMobileWebKit()Returns whether the user agent is Mobile WebKit-based.Mobile Webkit-based browsers include the Android Mobile WebKit and the iPhone Mobile WebKit browsers.
- See Also:
-
agentIsSafari
public boolean agentIsSafari()Returns whether the user agent is Safari.- See Also:
-
agentIsChrome
public boolean agentIsChrome()Returns whether the user agent is Chrome.- See Also:
-
agentIsGecko
public boolean agentIsGecko()Returns whether the user agent is Gecko-based.Gecko-based browsers include Firefox.
- See Also:
-
getServer
Returns the servlet.This returns the servlet environment of this session.
-
isInternalPathUsingFragments
public boolean isInternalPathUsingFragments()Returns whether internal paths are implemented using URI fragments.This may be the case for older non-HTML5 browsers which do not support HTML5 History APIs.
-
supportsCss3Animations
public boolean supportsCss3Animations()Returns whether this agent supports CSS3 animations. -
isTest
public boolean isTest()Returns whether this is a mocked test environment.
-