|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--org.apache.struts.util.RequestUtils
General purpose utility methods related to processing a servlet request in the Struts controller framework.
Field Summary | |
private static java.util.Locale |
defaultLocale
The default Locale for our server. |
private static MessageResources |
messages
The message resources for this package. |
Constructor Summary | |
RequestUtils()
|
Method Summary | |
static java.net.URL |
absoluteURL(javax.servlet.http.HttpServletRequest request,
java.lang.String path)
Create and return an absolute URL for the specified context-relative path, based on the server and context information in the specified request. |
static java.util.Map |
computeParameters(javax.servlet.jsp.PageContext pageContext,
java.lang.String paramId,
java.lang.String paramName,
java.lang.String paramProperty,
java.lang.String paramScope,
java.lang.String name,
java.lang.String property,
java.lang.String scope,
boolean transaction)
Compute a set of query parameters that will be dynamically added to a generated URL. |
static java.lang.String |
computeURL(javax.servlet.jsp.PageContext pageContext,
java.lang.String forward,
java.lang.String href,
java.lang.String page,
java.util.Map params,
java.lang.String anchor,
boolean redirect)
Compute a hyperlink URL based on the forward ,
href , or page parameter that is not null. |
static java.lang.Object |
lookup(javax.servlet.jsp.PageContext pageContext,
java.lang.String name,
java.lang.String scope)
Locate and return the specified bean, from an optionally specified scope, in the specified page context. |
static java.lang.Object |
lookup(javax.servlet.jsp.PageContext pageContext,
java.lang.String name,
java.lang.String property,
java.lang.String scope)
Locate and return the specified property of the specified bean, from an optionally specified scope, in the specified page context. |
static java.lang.String |
message(javax.servlet.jsp.PageContext pageContext,
java.lang.String bundle,
java.lang.String locale,
java.lang.String key)
Look up and return a message string, based on the specified parameters. |
static java.lang.String |
message(javax.servlet.jsp.PageContext pageContext,
java.lang.String bundle,
java.lang.String locale,
java.lang.String key,
java.lang.Object[] args)
Look up and return a message string, based on the specified parameters. |
static void |
populate(java.lang.Object bean,
javax.servlet.http.HttpServletRequest request)
Populate the properties of the specified JavaBean from the specified HTTP request, based on matching each parameter name against the corresponding JavaBeans "property setter" methods in the bean's class. |
static void |
populate(java.lang.Object bean,
java.lang.String prefix,
java.lang.String suffix,
javax.servlet.http.HttpServletRequest request)
Populate the properties of the specified JavaBean from the specified HTTP request, based on matching each parameter name (plus an optional prefix and/or suffix) against the corresponding JavaBeans "property setter" methods in the bean's class. |
static boolean |
present(javax.servlet.jsp.PageContext pageContext,
java.lang.String bundle,
java.lang.String locale,
java.lang.String key)
Return true if a message string for the specified message key is present for the specified Locale. |
static java.lang.String |
printableURL(java.net.URL url)
Compute the printable representation of a URL, leaving off the scheme/host/port part if no host is specified. |
static java.net.URL |
requestURL(javax.servlet.http.HttpServletRequest request)
Return the URL representing the current request. |
static void |
saveException(javax.servlet.jsp.PageContext pageContext,
java.lang.Throwable exception)
Save the specified exception as a request attribute for later use. |
static java.net.URL |
serverURL(javax.servlet.http.HttpServletRequest request)
Return the URL representing the scheme, server, and port number of the current request. |
Methods inherited from class java.lang.Object |
|
Field Detail |
private static final java.util.Locale defaultLocale
private static MessageResources messages
Constructor Detail |
public RequestUtils()
Method Detail |
public static java.net.URL absoluteURL(javax.servlet.http.HttpServletRequest request, java.lang.String path) throws java.net.MalformedURLException
request
- The servlet request we are processingpath
- The context-relative path (must start with '/')java.net.MalformedURLException
- if we cannot create an absolute URLpublic static java.util.Map computeParameters(javax.servlet.jsp.PageContext pageContext, java.lang.String paramId, java.lang.String paramName, java.lang.String paramProperty, java.lang.String paramScope, java.lang.String name, java.lang.String property, java.lang.String scope, boolean transaction) throws javax.servlet.jsp.JspException
<html:link>
tag. If no query parameters are
identified, return null
.pageContext
- PageContext we are operating inparamId
- Single-value request parameter name (if any)paramName
- Bean containing single-value parameter valueparamProperty
- Property (of bean named by paramName
containing single-value parameter valueparamScope
- Scope containing bean named by
paramScope
name
- Bean containing multi-value parameters Map (if any)property
- Property (of bean named by name
containing multi-value parameters Mapscope
- Scope containing bean named by
name
transaction
- Should we add our transaction control token?javax.servlet.jsp.JspException
- if we cannot look up the required beansjavax.servlet.jsp.JspException
- if a class cast exception occurs on a
looked-up bean or propertypublic static java.lang.String computeURL(javax.servlet.jsp.PageContext pageContext, java.lang.String forward, java.lang.String href, java.lang.String page, java.util.Map params, java.lang.String anchor, boolean redirect) throws java.net.MalformedURLException
forward
,
href
, or page
parameter that is not null.
The returned URL will have already been passed to
response.encodeURL()
for adding a session identifier.pageContext
- PageContext for the tag making this callforward
- Logical forward name for which to look up
the context-relative URI (if specified)href
- URL to be utilized unmodified (if specified)page
- Context-relative page for which a URL should
be created (if specified)params
- Map of parameters to be dynamically included (if any)anchor
- Anchor to be dynamically included (if any)redirect
- Is this URL for a response.sendRedirect()
?java.net.MalformedURLException
- if a URL cannot be created
for the specified parameterspublic static java.lang.Object lookup(javax.servlet.jsp.PageContext pageContext, java.lang.String name, java.lang.String scope) throws javax.servlet.jsp.JspException
null
instead. If an exception is thrown, it will
have already been saved via a call to saveException()
.pageContext
- Page context to be searchedname
- Name of the bean to be retrievedscope
- Scope to be searched (page, request, session, application)
or null
to use findAttribute()
insteadjavax.servlet.jsp.JspException
- if an invalid scope name
is requestedpublic static java.lang.Object lookup(javax.servlet.jsp.PageContext pageContext, java.lang.String name, java.lang.String property, java.lang.String scope) throws javax.servlet.jsp.JspException
saveException()
.pageContext
- Page context to be searchedname
- Name of the bean to be retrievedproperty
- Name of the property to be retrieved, or
null
to retrieve the bean itselfscope
- Scope to be searched (page, request, session, application)
or null
to use findAttribute()
insteadjavax.servlet.jsp.JspException
- if an invalid scope name
is requestedjavax.servlet.jsp.JspException
- if the specified bean is not foundjavax.servlet.jsp.JspException
- if accessing this property causes an
IllegalAccessException, IllegalArgumentException,
InvocationTargetException, or NoSuchMethodExceptionpublic static java.lang.String message(javax.servlet.jsp.PageContext pageContext, java.lang.String bundle, java.lang.String locale, java.lang.String key) throws javax.servlet.jsp.JspException
pageContext
- The PageContext associated with this requestbundle
- Name of the servlet context attribute for our
message resources bundlelocale
- Name of the session attribute for our user's Localekey
- Message key to be looked up and returnedjavax.servlet.jsp.JspException
- if a lookup error occurs (will have been
saved in the request already)public static java.lang.String message(javax.servlet.jsp.PageContext pageContext, java.lang.String bundle, java.lang.String locale, java.lang.String key, java.lang.Object[] args) throws javax.servlet.jsp.JspException
pageContext
- The PageContext associated with this requestbundle
- Name of the servlet context attribute for our
message resources bundlelocale
- Name of the session attribute for our user's Localekey
- Message key to be looked up and returnedargs
- Replacement parameters for this messagejavax.servlet.jsp.JspException
- if a lookup error occurs (will have been
saved in the request already)public static void populate(java.lang.Object bean, javax.servlet.http.HttpServletRequest request) throws javax.servlet.ServletException
convert()
.bean
- The JavaBean whose properties are to be setrequest
- The HTTP request whose parameters are to be used
to populate bean propertiesjavax.servlet.ServletException
- if an exception is thrown while setting
property valuespublic static void populate(java.lang.Object bean, java.lang.String prefix, java.lang.String suffix, javax.servlet.http.HttpServletRequest request) throws javax.servlet.ServletException
setProperties()
.
If you specify a non-null prefix
and a non-null
suffix
, the parameter name must match both
conditions for its value(s) to be used in populating bean properties.
If the request's content type is "multipart/form-data" and the
method is "POST", the HttpServletRequest object will be wrapped in
a MultipartRequestWrapper object.
bean
- The JavaBean whose properties are to be setprefix
- The prefix (if any) to be prepend to bean property
names when looking for matching parameterssuffix
- The suffix (if any) to be appended to bean property
names when looking for matching parametersrequest
- The HTTP request whose parameters are to be used
to populate bean propertiesjavax.servlet.ServletException
- if an exception is thrown while setting
property valuespublic static boolean present(javax.servlet.jsp.PageContext pageContext, java.lang.String bundle, java.lang.String locale, java.lang.String key) throws javax.servlet.jsp.JspException
pageContext
- The PageContext associated with this requestbundle
- Name of the servlet context attribute for our
message resources bundlelocale
- Name of the session attribute for our user's Localekey
- Message key to be looked up and returnedjavax.servlet.jsp.JspException
- if a lookup error occurs (will have been
saved in the request already)public static java.lang.String printableURL(java.net.URL url)
url
- URL to render in a printable representationpublic static java.net.URL requestURL(javax.servlet.http.HttpServletRequest request) throws java.net.MalformedURLException
HttpServletRequest.getRequestURL()
in Servlet 2.3.request
- The servlet request we are processingjava.net.MalformedURLException
- if a URL cannot be createdpublic static java.net.URL serverURL(javax.servlet.http.HttpServletRequest request) throws java.net.MalformedURLException
request
- The servlet request we are processingjava.net.MalformedURLException
- if a URL cannot be createdpublic static void saveException(javax.servlet.jsp.PageContext pageContext, java.lang.Throwable exception)
pageContext
- The PageContext for the current pageexception
- The exception to be saved
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |