- java.lang.Object
-
- org.omnifaces.util.Servlets
-
public final class Servlets extends Object
Collection of utility methods for the Servlet API in general. Most of them are internally used by
Faces
andFacesLocal
, however they may also be useful in a "plain vanilla" servlet or servlet filter.There are as of now also five special methods related to Faces without needing a
FacesContext
:- The
getFacesLifecycle(ServletContext)
which returns the Faces lifecycle, allowing you a.o. to programmatically register Faces application's phase listeners. - The
isFacesAjaxRequest(HttpServletRequest)
which is capable of checking if the current request is a Faces ajax request. - The
isFacesResourceRequest(HttpServletRequest)
which is capable of checking if the current request is a Faces resource request. - The
facesRedirect(HttpServletRequest, HttpServletResponse, String, Object...)
which is capable of distinguishing Faces ajax requests from regular requests and altering the redirect logic on it, exactly like asExternalContext.redirect(String)
does. In other words, this method behaves exactly the same asFaces.redirect(String, Object...)
. - The
isFacesDevelopment(ServletContext)
which is capable of checking if the current Faces application configuration is set to development project stage.
Those methods can be used in for example a servlet filter.
For a full list, check the method summary.
- Since:
- 1.6
- Author:
- Arjan Tijms, Bauke Scholtz
- The
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addResponseCookie(HttpServletRequest request, HttpServletResponse response, String name, String value, int maxAge)
Add a cookie with given name, value and maxage to the HTTP response.static void
addResponseCookie(HttpServletRequest request, HttpServletResponse response, String name, String value, String path, int maxAge)
Add a cookie with given name, value, path and maxage to the HTTP response.static void
addResponseCookie(HttpServletRequest request, HttpServletResponse response, String name, String value, String domain, String path, int maxAge)
Add a cookie with given name, value, domain, path and maxage to the HTTP response.static void
facesRedirect(HttpServletRequest request, HttpServletResponse response, String url, Object... paramValues)
Sends a temporary (302) Faces redirect to the given URL, supporting Faces ajax requests.static String
formatContentDispositionHeader(String filename, boolean attachment)
Format an UTF-8 compatible content disposition header for the given filename and whether it's an attachment.static <T> T
getApplicationAttribute(ServletContext context, String name)
Returns the application scope attribute value associated with the given name.static ServletContext
getContext()
Returns the servlet context.static Lifecycle
getFacesLifecycle(ServletContext context)
Returns TheLifecycle
associated with current Faces application.static Map<String,List<String>>
getMutableRequestHeaderMap(HttpServletRequest request)
Returns the mutable request header map.static Map<String,List<String>>
getMutableRequestParameterMap(HttpServletRequest request)
Returns the mutable request parameter map.static String
getReferrer(HttpServletRequest request)
Returns the referrer of the request.static String
getRemoteAddr(HttpServletRequest request)
Returns the Internet Protocol (IP) address of the client that sent the request.static String
getRequestBaseURL(HttpServletRequest request)
Returns the HTTP request base URL.static String
getRequestCookie(HttpServletRequest request, String name)
Returns the value of the HTTP request cookie associated with the given name.static String
getRequestDomainURL(HttpServletRequest request)
Returns the HTTP request domain URL.static String
getRequestHostname(HttpServletRequest request)
Returns the HTTP request hostname.static Map<String,List<String>>
getRequestParameterMap(HttpServletRequest request)
Returns the HTTP request parameter map.static String
getRequestPathInfo(HttpServletRequest request)
Returns the HTTP request path info, taking into account whether FacesViews is used with MultiViews enabled.static String
getRequestQueryString(HttpServletRequest request)
Returns the HTTP request query string, regardless of any forward.static Map<String,List<String>>
getRequestQueryStringMap(HttpServletRequest request)
Returns the HTTP request query string as parameter values map.static String
getRequestRelativeURI(HttpServletRequest request)
Returns the HTTP request URI relative to the context root, regardless of any forward.static String
getRequestRelativeURIWithoutPathParameters(HttpServletRequest request)
Returns the HTTP request URI relative to the context root without path parameters, regardless of any forward.static String
getRequestURI(HttpServletRequest request)
Returns the HTTP request URI, regardless of any forward or error dispatch.static String
getRequestURIWithQueryString(HttpServletRequest request)
Returns the HTTP request URI with query string, regardless of any forward.static String
getRequestURL(HttpServletRequest request)
Returns the HTTP request URL with query string, regardless of any forward.static String
getRequestURLWithQueryString(HttpServletRequest request)
Returns the HTTP request URL with query string.static String
getSubmittedFileName(Part part)
Returns the submitted file name of the given part, making sure that any path is stripped off.static String
getUserAgent(HttpServletRequest request)
Returns the User-Agent string of the client.static URL
getWebXmlURL(ServletContext context)
Returns URL ofweb.xml
file used in current application.static Map<String,String>
headerToMap(String header)
Returns a mapping of given semicolon-separated request header.static boolean
isFacesAjaxRequest(HttpServletRequest request)
Returnstrue
if the given HTTP servlet request is a Faces ajax request.static boolean
isFacesDevelopment(ServletContext context)
Returnstrue
if we're in Faces development stage.static boolean
isFacesResourceRequest(HttpServletRequest request)
Returnstrue
if the given HTTP servlet request is a Faces resource request.static boolean
isProxied(HttpServletRequest request)
Returnstrue
if request is proxied,false
otherwise.static boolean
isSecure(HttpServletRequest request)
Returnstrue
if connection is secure,false
otherwise.static void
redirectPermanent(HttpServletResponse response, String url)
Sends a permanent (301) redirect to the given URL.static void
removeResponseCookie(HttpServletRequest request, HttpServletResponse response, String name, String path)
Remove the cookie with given name and path from the HTTP response.static void
setCacheHeaders(HttpServletResponse response, long expires)
Set the cache headers.static void
setNoCacheHeaders(HttpServletResponse response)
Set the no-cache headers.static Map<String,List<String>>
toParameterMap(String queryString)
Converts the given request query string to request parameter values map.static String
toQueryString(List<? extends ParamHolder<?>> params)
Converts the given parameter values list to request query string.static String
toQueryString(Map<String,List<String>> parameterMap)
Converts the given request parameter values map to request query string.
-
-
-
Method Detail
-
getRequestHostname
public static String getRequestHostname(HttpServletRequest request)
Returns the HTTP request hostname. This is the entire domain, without any scheme and slashes. Noted should be that this value is extracted from the request URL, not fromServletRequest.getServerName()
as its outcome can be influenced by proxies.- Parameters:
request
- The involved HTTP servlet request.- Returns:
- The HTTP request hostname.
- Throws:
IllegalArgumentException
- When the URL is malformed. This is however unexpected as the request would otherwise not have hit the server at all.- See Also:
HttpServletRequest.getRequestURL()
-
getRequestDomainURL
public static String getRequestDomainURL(HttpServletRequest request)
Returns the HTTP request domain URL. This is the URL with the scheme and domain, without any trailing slash.- Parameters:
request
- The involved HTTP servlet request.- Returns:
- The HTTP request domain URL.
- Throws:
IllegalArgumentException
- When the URL is malformed. This is however unexpected as the request would otherwise not have hit the server at all.- See Also:
HttpServletRequest.getRequestURL()
-
getRequestBaseURL
public static String getRequestBaseURL(HttpServletRequest request)
Returns the HTTP request base URL. This is the URL from the scheme, domain until with context path, including the trailing slash. This is the value you could use in HTML<base>
tag.- Parameters:
request
- The involved HTTP servlet request.- Returns:
- The HTTP request base URL.
- See Also:
HttpServletRequest.getRequestURL()
,HttpServletRequest.getRequestURI()
,HttpServletRequest.getContextPath()
-
getRequestURI
public static String getRequestURI(HttpServletRequest request)
Returns the HTTP request URI, regardless of any forward or error dispatch. This is the part after the domain in the request URL, including the leading slash.- Parameters:
request
- The involved HTTP servlet request.- Returns:
- The HTTP request URI, regardless of any forward or error dispatch.
- Since:
- 2.4
- See Also:
HttpServletRequest.getRequestURI()
,RequestDispatcher.FORWARD_REQUEST_URI
,RequestDispatcher.ERROR_REQUEST_URI
-
getRequestPathInfo
public static String getRequestPathInfo(HttpServletRequest request)
Returns the HTTP request path info, taking into account whether FacesViews is used with MultiViews enabled. If the resource is prefix mapped (e.g./faces/*
), then this returns the whole part after the prefix mapping, with a leading slash. If the resource is suffix mapped (e.g.*.xhtml
), then this returnsnull
.- Parameters:
request
- The involved HTTP servlet request.- Returns:
- The HTTP request path info.
- Since:
- 2.5
- See Also:
HttpServletRequest.getPathInfo()
,FacesViews.FACES_VIEWS_ORIGINAL_PATH_INFO
-
getRequestQueryString
public static String getRequestQueryString(HttpServletRequest request)
Returns the HTTP request query string, regardless of any forward.- Parameters:
request
- The involved HTTP servlet request.- Returns:
- The HTTP request query string, regardless of any forward.
- Since:
- 2.4
- See Also:
HttpServletRequest.getRequestURI()
,RequestDispatcher.FORWARD_QUERY_STRING
-
getRequestQueryStringMap
public static Map<String,List<String>> getRequestQueryStringMap(HttpServletRequest request)
Returns the HTTP request query string as parameter values map. Note this method returns only the request URL (GET) parameters, as opposed toServletRequest.getParameterMap()
, which contains both the request URL (GET) parameters and and the request body (POST) parameters. The map entries are in the same order as they appear in the query string.- Parameters:
request
- The involved HTTP servlet request.- Returns:
- The HTTP request query string as parameter values map.
-
getRequestParameterMap
public static Map<String,List<String>> getRequestParameterMap(HttpServletRequest request)
Returns the HTTP request parameter map. Note this method returns the values as aList<String>
, as opposed toServletRequest.getParameterMap()
, which returns the values asString[]
. The map entries are not per definition ordered, but the values are.- Parameters:
request
- The involved HTTP servlet request.- Returns:
- The HTTP request parameter map.
- Since:
- 2.6
-
getMutableRequestParameterMap
public static Map<String,List<String>> getMutableRequestParameterMap(HttpServletRequest request)
Returns the mutable request parameter map. This requires installation ofMutableRequestFilter
.- Parameters:
request
- The involved HTTP servlet request.- Returns:
- The mutable request parameter map.
- Throws:
IllegalStateException
- When theMutableRequestFilter
is not installed or not invoked yet.- Since:
- 3.14
- See Also:
MutableRequestFilter.getMutableRequest(HttpServletRequest)
,MutableRequestFilter.MutableRequest.getMutableParameterMap()
-
getRequestURIWithQueryString
public static String getRequestURIWithQueryString(HttpServletRequest request)
Returns the HTTP request URI with query string, regardless of any forward. This is the part after the domain in the request URL, including the leading slash and the request query string.- Parameters:
request
- The involved HTTP servlet request.- Returns:
- The HTTP request URI with query string.
- See Also:
getRequestURI(HttpServletRequest)
,getRequestQueryString(HttpServletRequest)
-
getRequestRelativeURI
public static String getRequestRelativeURI(HttpServletRequest request)
Returns the HTTP request URI relative to the context root, regardless of any forward. This is the request URI minus the context path. Note that this includes path parameters.- Parameters:
request
- The involved HTTP servlet request.- Returns:
- The HTTP request URI relative to the context root.
- Since:
- 1.8
-
getRequestRelativeURIWithoutPathParameters
public static String getRequestRelativeURIWithoutPathParameters(HttpServletRequest request)
Returns the HTTP request URI relative to the context root without path parameters, regardless of any forward. This is the request URI minus the context path and path parameters.- Parameters:
request
- The involved HTTP servlet request.- Returns:
- The HTTP request URI relative to the context root without path parameters.
- Since:
- 1.8
-
getRequestURL
public static String getRequestURL(HttpServletRequest request)
Returns the HTTP request URL with query string, regardless of any forward. This is the full request URL without query string as the enduser sees in browser address bar.- Parameters:
request
- The involved HTTP servlet request.- Returns:
- The HTTP request URL without query string, regardless of any forward.
- Since:
- 2.4
- See Also:
HttpServletRequest.getRequestURL()
-
getRequestURLWithQueryString
public static String getRequestURLWithQueryString(HttpServletRequest request)
Returns the HTTP request URL with query string. This is the full request URL with query string as the enduser sees in browser address bar.- Parameters:
request
- The involved HTTP servlet request.- Returns:
- The HTTP request URL with query string, regardless of any forward.
- See Also:
HttpServletRequest.getRequestURL()
,HttpServletRequest.getQueryString()
-
toParameterMap
public static Map<String,List<String>> toParameterMap(String queryString)
Converts the given request query string to request parameter values map.- Parameters:
queryString
- The request query string.- Returns:
- The request query string as request parameter values map.
- Since:
- 1.7
-
toQueryString
public static String toQueryString(Map<String,List<String>> parameterMap)
Converts the given request parameter values map to request query string. Empty names and null values will be skipped.- Parameters:
parameterMap
- The request parameter values map.- Returns:
- The request parameter values map as request query string.
- Since:
- 2.0
-
toQueryString
public static String toQueryString(List<? extends ParamHolder<?>> params)
Converts the given parameter values list to request query string. Empty names and null values will be skipped.- Parameters:
params
- The parameter values list.- Returns:
- The parameter values list as request query string.
- Since:
- 2.2
-
getRemoteAddr
public static String getRemoteAddr(HttpServletRequest request)
Returns the Internet Protocol (IP) address of the client that sent the request. This will first check theForwarded
andX-Forwarded-For
request headers and if any is present, then return its first IP address, else just returnServletRequest.getRemoteAddr()
unmodified.- Parameters:
request
- The involved HTTP servlet request.- Returns:
- The IP address of the client.
- Since:
- 2.3
- See Also:
ServletRequest.getRemoteAddr()
-
isProxied
public static boolean isProxied(HttpServletRequest request)
Returnstrue
if request is proxied,false
otherwise. In other words, returnstrue
when eitherForwarded
orX-Forwarded-For
request headers is present.- Parameters:
request
- The involved HTTP servlet request.- Returns:
true
if request is proxied,false
otherwise.- Since:
- 3.6
- See Also:
HttpServletRequest.getHeader(String)
-
getUserAgent
public static String getUserAgent(HttpServletRequest request)
Returns the User-Agent string of the client.- Parameters:
request
- The involved HTTP servlet request.- Returns:
- The User-Agent string of the client.
- Since:
- 3.2
- See Also:
HttpServletRequest.getHeader(String)
-
getReferrer
public static String getReferrer(HttpServletRequest request)
Returns the referrer of the request.- Parameters:
request
- The involved HTTP servlet request.- Returns:
- The referrer of the request.
- Since:
- 3.10
- See Also:
HttpServletRequest.getHeader(String)
-
isSecure
public static boolean isSecure(HttpServletRequest request)
Returnstrue
if connection is secure,false
otherwise. This method will first check ifServletRequest.isSecure()
returnstrue
, and if nottrue
, check if theX-Forwarded-Proto
is present and equals tohttps
.- Parameters:
request
- The involved HTTP servlet request.- Returns:
true
if connection is secure,false
otherwise.- Since:
- 3.0
- See Also:
ServletRequest.isSecure()
-
getSubmittedFileName
public static String getSubmittedFileName(Part part)
Returns the submitted file name of the given part, making sure that any path is stripped off. Some browsers are known to incorrectly include the client side path along with it. Since version 2.6.7, RFC 2231/5987 encoded file names are also supported.- Parameters:
part
- The part of a multipart/form-data request.- Returns:
- The submitted file name of the given part, or null if there is none.
- Since:
- 2.5
-
headerToMap
public static Map<String,String> headerToMap(String header)
Returns a mapping of given semicolon-separated request header. The returned map is unordered and unmodifiable.- Parameters:
header
- Any semicolon-separated request header, e.g.Content-Disposition
.- Returns:
- A mapping of given semicolon-separated request header.
- Since:
- 3.0
-
getMutableRequestHeaderMap
public static Map<String,List<String>> getMutableRequestHeaderMap(HttpServletRequest request)
Returns the mutable request header map. This requires installation ofMutableRequestFilter
.- Parameters:
request
- The involved HTTP servlet request.- Returns:
- The mutable request header map.
- Throws:
IllegalStateException
- When theMutableRequestFilter
is not installed or not invoked yet.- Since:
- 3.14
- See Also:
MutableRequestFilter.getMutableRequest(HttpServletRequest)
,MutableRequestFilter.MutableRequest.getMutableHeaderMap()
-
setCacheHeaders
public static void setCacheHeaders(HttpServletResponse response, long expires)
Set the cache headers. If the
expires
argument is larger than 0 seconds, then the following headers will be set:Cache-Control: public,max-age=[expiration time in seconds],must-revalidate
Expires: [expiration date of now plus expiration time in seconds]
Else the method will delegate to
setNoCacheHeaders(HttpServletResponse)
.- Parameters:
response
- The HTTP servlet response to set the headers on.expires
- The expire time in seconds (not milliseconds!).- Since:
- 2.2
-
setNoCacheHeaders
public static void setNoCacheHeaders(HttpServletResponse response)
Set the no-cache headers. The following headers will be set:
Cache-Control: no-cache,no-store,must-revalidate
Expires: [expiration date of 0]
Pragma: no-cache
- Parameters:
response
- The HTTP servlet response to set the headers on.- Since:
- 2.2
-
formatContentDispositionHeader
public static String formatContentDispositionHeader(String filename, boolean attachment)
Format an UTF-8 compatible content disposition header for the given filename and whether it's an attachment.
- Parameters:
filename
- The filename to appear in "Save As" dialogue.attachment
- Whether the content should be provided as an attachment or inline.- Returns:
- An UTF-8 compatible content disposition header.
- Since:
- 2.6
-
redirectPermanent
public static void redirectPermanent(HttpServletResponse response, String url)
Sends a permanent (301) redirect to the given URL.- Parameters:
response
- The involved HTTP servlet response.url
- The URL to permanently redirect the current response to.- Since:
- 3.6
- See Also:
HttpServletResponse.setStatus(int)
,HttpServletResponse.setHeader(String, String)
-
getRequestCookie
public static String getRequestCookie(HttpServletRequest request, String name)
Returns the value of the HTTP request cookie associated with the given name. The value is implicitly URL-decoded with a charset of UTF-8.- Parameters:
request
- The involved HTTP servlet request.name
- The HTTP request cookie name.- Returns:
- The value of the HTTP request cookie associated with the given name.
- Throws:
UnsupportedOperationException
- When this platform does not support UTF-8.- Since:
- 2.0
- See Also:
HttpServletRequest.getCookies()
-
addResponseCookie
public static void addResponseCookie(HttpServletRequest request, HttpServletResponse response, String name, String value, int maxAge)
Add a cookie with given name, value and maxage to the HTTP response. The cookie value will implicitly be URL-encoded with UTF-8 so that any special characters can be stored. The cookie will implicitly be set in the domain and path of the current request URL. The cookie will implicitly be set to HttpOnly as JavaScript is not supposed to manipulate server-created cookies. The cookie will implicitly be set to secure when the current request is a HTTPS request.- Parameters:
request
- The involved HTTP servlet request.response
- The involved HTTP servlet response.name
- The cookie name.value
- The cookie value.maxAge
- The maximum age of the cookie, in seconds. If this is0
, then the cookie will be removed. Note that the name and path must be exactly the same as it was when the cookie was created. If this is-1
then the cookie will become a session cookie and thus live as long as the established HTTP session.- Throws:
UnsupportedOperationException
- When this platform does not support UTF-8.- Since:
- 2.0
- See Also:
HttpServletResponse.addCookie(Cookie)
-
addResponseCookie
public static void addResponseCookie(HttpServletRequest request, HttpServletResponse response, String name, String value, String path, int maxAge)
Add a cookie with given name, value, path and maxage to the HTTP response. The cookie value will implicitly be URL-encoded with UTF-8 so that any special characters can be stored. The cookie will implicitly be set in the domain of the current request URL. The cookie will implicitly be set to HttpOnly as JavaScript is not supposed to manipulate server-created cookies. The cookie will implicitly be set to secure when the current request is a HTTPS request.- Parameters:
request
- The involved HTTP servlet request.response
- The involved HTTP servlet response.name
- The cookie name.value
- The cookie value.path
- The cookie path. If this is/
, then the cookie is available in all pages of the webapp. If this is/somespecificpath
, then the cookie is only available in pages under the specified path.maxAge
- The maximum age of the cookie, in seconds. If this is0
, then the cookie will be removed. Note that the name and path must be exactly the same as it was when the cookie was created. If this is-1
then the cookie will become a session cookie and thus live as long as the established HTTP session.- Throws:
UnsupportedOperationException
- When this platform does not support UTF-8.- Since:
- 2.0
- See Also:
HttpServletResponse.addCookie(Cookie)
-
addResponseCookie
public static void addResponseCookie(HttpServletRequest request, HttpServletResponse response, String name, String value, String domain, String path, int maxAge)
Add a cookie with given name, value, domain, path and maxage to the HTTP response. The cookie value will implicitly be URL-encoded with UTF-8 so that any special characters can be stored. The cookie will implicitly be set to HttpOnly as JavaScript is not supposed to manipulate server-created cookies. The cookie will implicitly be set to secure when the current request is a HTTPS request.- Parameters:
request
- The involved HTTP servlet request.response
- The involved HTTP servlet response.name
- The cookie name.value
- The cookie value.domain
- The cookie domain. You can use.example.com
(with a leading period) if you'd like the cookie to be available to all subdomains of the domain. Note that you cannot set it to a different domain.path
- The cookie path. If this is/
, then the cookie is available in all pages of the webapp. If this is/somespecificpath
, then the cookie is only available in pages under the specified path.maxAge
- The maximum age of the cookie, in seconds. If this is0
, then the cookie will be removed. Note that the name and path must be exactly the same as it was when the cookie was created. If this is-1
then the cookie will become a session cookie and thus live as long as the established HTTP session.- Throws:
UnsupportedOperationException
- When this platform does not support UTF-8.- Since:
- 2.0
- See Also:
HttpServletResponse.addCookie(Cookie)
-
removeResponseCookie
public static void removeResponseCookie(HttpServletRequest request, HttpServletResponse response, String name, String path)
Remove the cookie with given name and path from the HTTP response. Note that the name and path must be exactly the same as it was when the cookie was created.- Parameters:
request
- The involved HTTP servlet request.response
- The involved HTTP servlet response.name
- The cookie name.path
- The cookie path.- Since:
- 2.0
- See Also:
HttpServletResponse.addCookie(Cookie)
-
getContext
public static ServletContext getContext()
Returns the servlet context. If the Faces context is available, then return it from there. Else if the CDI bean manager is available, then return it from there.- Returns:
- The servlet context.
- Since:
- 3.10
- See Also:
Faces.getServletContext()
,Beans.getInstance(Bean, boolean)
-
getApplicationAttribute
public static <T> T getApplicationAttribute(ServletContext context, String name)
Returns the application scope attribute value associated with the given name.- Type Parameters:
T
- The expected return type.- Parameters:
context
- The servlet context used for looking up the attribute.name
- The application scope attribute name.- Returns:
- The application scope attribute value associated with the given name.
- Throws:
ClassCastException
- WhenT
is of wrong type.- See Also:
ServletContext.getAttribute(String)
-
getFacesLifecycle
public static Lifecycle getFacesLifecycle(ServletContext context)
Returns TheLifecycle
associated with current Faces application.- Parameters:
context
- The involved servlet context.- Returns:
- The
Lifecycle
associated with current Faces application. - Since:
- 2.5
- See Also:
LifecycleFactory.getLifecycle(String)
-
isFacesAjaxRequest
public static boolean isFacesAjaxRequest(HttpServletRequest request)
Returnstrue
if the given HTTP servlet request is a Faces ajax request. This does exactly the same asFaces.isAjaxRequest()
, but then without the need for aFacesContext
. The major advantage is that you can perform the job inside a servlet filter, where theFacesContext
is normally not available.- Parameters:
request
- The involved HTTP servlet request.- Returns:
true
if the given HTTP servlet request is a Faces ajax request.- Since:
- 2.0
-
isFacesResourceRequest
public static boolean isFacesResourceRequest(HttpServletRequest request)
Returnstrue
if the given HTTP servlet request is a Faces resource request. I.e. this request will trigger the FacesResourceHandler
for among others CSS/JS/image resources.- Parameters:
request
- The involved HTTP servlet request.- Returns:
true
if the given HTTP servlet request is a Faces resource request.- Since:
- 2.0
- See Also:
ResourceHandler.RESOURCE_IDENTIFIER
-
isFacesDevelopment
public static boolean isFacesDevelopment(ServletContext context)
Returnstrue
if we're in Faces development stage. This will be the case when thejakarta.faces.PROJECT_STAGE
context parameter inweb.xml
is set toDevelopment
.- Parameters:
context
- The involved servlet context.- Returns:
true
if we're in development stage, otherwisefalse
.- Since:
- 2.1
- See Also:
Application.getProjectStage()
-
facesRedirect
public static void facesRedirect(HttpServletRequest request, HttpServletResponse response, String url, Object... paramValues)
Sends a temporary (302) Faces redirect to the given URL, supporting Faces ajax requests. This does exactly the same asFaces.redirect(String, Object...)
, but without the need for aFacesContext
. The major advantage is that you can perform the job inside a servlet filter or even a plain vanilla servlet, where theFacesContext
is normally not available. This method also recognizes Faces ajax requests which requires a special XML response in order to successfully perform the redirect.If the given URL does not start with
http://
,https://
or/
, then the request context path will be prepended, otherwise it will be the unmodified redirect URL. So, when redirecting to another page in the same web application, always specify the full path from the context root on (which in turn does not need to start with/
).Servlets.facesRedirect(request, response, "some.xhtml");
You can use
String.format(String, Object...)
placeholder%s
in the redirect URL to represent placeholders for any request parameter values which needs to be URL-encoded. Here's a concrete example:Servlets.facesRedirect(request, response, "some.xhtml?foo=%s&bar=%s", foo, bar);
- Parameters:
request
- The involved HTTP servlet request.response
- The involved HTTP servlet response.url
- The URL to redirect the current response to.paramValues
- The request parameter values which you'd like to put URL-encoded in the given URL.- Throws:
UncheckedIOException
- Whenever something fails at I/O level.- Since:
- 2.0
-
getWebXmlURL
public static URL getWebXmlURL(ServletContext context) throws IOException
Returns URL ofweb.xml
file used in current application. This also takes into account the Quarkus location inMETA-INF
folder.- Parameters:
context
- The involved servlet context.- Returns:
- URL of
web.xml
file used in current application. - Throws:
IOException
- Since:
- 3.14
-
-