org.apache.struts.util

Class RequestUtils

public class RequestUtils extends Object

General purpose utility methods related to processing a servlet request in the Struts controller framework.

Version: $Rev: 384422 $ $Date: 2006-03-09 04:17:18 +0000 (Thu, 09 Mar 2006) $

Field Summary
protected static Loglog

Commons Logging instance.

Method Summary
static URLabsoluteURL(HttpServletRequest request, 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 StringactionURL(HttpServletRequest request, ActionConfig action, String pattern)

Return the context-relative URL that corresponds to the specified {@link ActionConfig}, relative to the module associated with the current modules's {@link ModuleConfig}.

static ClassapplicationClass(String className)

Return the Class object for the specified fully qualified class name, from this web application's class loader.

static ObjectapplicationInstance(String className)

Return a new instance of the specified fully qualified class name, after loading the class from this web application's class loader.

static booleancanReuseActionForm(ActionForm instance, FormBeanConfig config)

Determine whether instance of ActionForm is suitable for re-use as an instance of the form described by config.

static MapcomputeParameters(PageContext pageContext, String paramId, String paramName, String paramProperty, String paramScope, String name, String property, String scope, boolean transaction)

Compute a set of query parameters that will be dynamically added to a generated URL.

static StringcomputeURL(PageContext pageContext, String forward, String href, String page, Map params, String anchor, boolean redirect)

Compute a hyperlink URL based on the forward, href or page parameter that is not null.

static StringcomputeURL(PageContext pageContext, String forward, String href, String page, String action, Map params, String anchor, boolean redirect)

Compute a hyperlink URL based on the forward, href, action or page parameter that is not null.

static StringcomputeURL(PageContext pageContext, String forward, String href, String page, String action, Map params, String anchor, boolean redirect, boolean encodeSeparator)

Compute a hyperlink URL based on the forward, href, action or page parameter that is not null.

static ActionFormcreateActionForm(HttpServletRequest request, ActionMapping mapping, ModuleConfig moduleConfig, ActionServlet servlet)

Create (if necessary) and return an ActionForm instance appropriate for this request.

static ActionFormcreateActionForm(FormBeanConfig config, ActionServlet servlet)

Create and return an ActionForm instance appropriate to the information in config.

Does not perform any checks to see if an existing ActionForm exists which could be reused.

static StringBuffercreateServerStringBuffer(String scheme, String server, int port)

Return StringBuffer representing the scheme, server, and port number of the current request.

static StringBuffercreateServerUriStringBuffer(String scheme, String server, int port, String uri)

Return StringBuffer representing the scheme, server, and port number of the current request.

static StringencodeURL(String url)

Use the new URLEncoder.encode method from Java 1.4 if available, else use the old deprecated version.

static StringforwardURL(HttpServletRequest request, ForwardConfig forward)

Return the context-relative URL that corresponds to the specified ForwardConfig.

static StringforwardURL(HttpServletRequest request, ForwardConfig forward, ModuleConfig moduleConfig)

Return the context-relative URL that corresponds to the specified ForwardConfig.

static ActionErrorsgetActionErrors(PageContext pageContext, String paramName)

Retrieves the value from request scope and if it isn't already an ErrorMessages some classes are converted to one.

static StringgetActionMappingName(String action)

Return the form action converted into an action mapping path.

static StringgetActionMappingURL(String action, PageContext pageContext)

Return the form action converted into a server-relative URL.

static ActionMessagesgetActionMessages(PageContext pageContext, String paramName)

Retrieves the value from request scope and if it isn't already an ActionMessages some classes are converted to one.

static MapgetAllParametersForMultipartRequest(HttpServletRequest request, MultipartRequestHandler multipartHandler)

Create a Map containing all of the parameters supplied for a multipart request, keyed by parameter name.

static ModuleConfiggetModuleConfig(HttpServletRequest request, ServletContext context)

Return the ModuleConfig object is it exists, null otherwise.

static ModuleConfiggetModuleConfig(PageContext pageContext)

Return the ModuleConfig object if it exists, null if otherwise.

static StringgetModuleName(HttpServletRequest request, ServletContext context)
Get the module name to which the specified request belong.
static StringgetModuleName(String matchPath, ServletContext context)

Get the module name to which the specified uri belong.

static String[]getModulePrefixes(ServletContext context)

Return the list of module prefixes that are defined for this web application.

static MultipartRequestHandlergetMultipartHandler(HttpServletRequest request)

Try to locate a multipart request handler for this request.

static ModuleConfiggetRequestModuleConfig(HttpServletRequest request)

Return the current ModuleConfig object stored in request, if it exists, null otherwise.

static intgetScope(String scopeName)

Converts the scope name into its corresponding PageContext constant value.

static LocalegetUserLocale(HttpServletRequest request, String locale)

Look up and return current user locale, based on the specified parameters.

static booleanisXhtml(PageContext pageContext)

Returns true if the custom tags are in XHTML mode.

static Objectlookup(PageContext pageContext, String name, String scopeName)

Locate and return the specified bean, from an optionally specified scope, in the specified page context.

static Objectlookup(PageContext pageContext, String name, String property, String scope)

Locate and return the specified property of the specified bean, from an optionally specified scope, in the specified page context.

static ActionFormlookupActionForm(HttpServletRequest request, String attribute, String scope)
static Stringmessage(PageContext pageContext, String bundle, String locale, String key)

Look up and return a message string, based on the specified parameters.

static Stringmessage(PageContext pageContext, String bundle, String locale, String key, Object[] args)
Look up and return a message string, based on the specified parameters.
static StringpageURL(HttpServletRequest request, String page)

Return the context-relative URL that corresponds to the specified page attribute value, calculated based on the pagePattern property of the current module's {@link ModuleConfig}.

static voidpopulate(Object bean, 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 voidpopulate(Object bean, String prefix, String suffix, 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 booleanpresent(PageContext pageContext, String bundle, String locale, String key)

Return true if a message string for the specified message key is present for the specified Locale.

static StringprintableURL(URL url)

Compute the printable representation of a URL, leaving off the scheme/host/port part if no host is specified.

static StringBufferrequestToServerStringBuffer(HttpServletRequest request)

Return StringBuffer representing the scheme, server, and port number of the current request.

static StringBufferrequestToServerUriStringBuffer(HttpServletRequest request)

Return the string representing the scheme, server, and port number of the current request.

static URLrequestURL(HttpServletRequest request)

Return the URL representing the current request.

static LocaleretrieveUserLocale(PageContext pageContext, String locale)

Look up and return current user locale, based on the specified parameters.

static voidsaveException(PageContext pageContext, Throwable exception)

Save the specified exception as a request attribute for later use.

static voidselectModule(String prefix, HttpServletRequest request, ServletContext context)

Select the module to which the specified request belongs, and add corresponding request attributes to this request.

static voidselectModule(HttpServletRequest request, ServletContext context)

Select the module to which the specified request belongs, and add corresponding request attributes to this request.

static URLserverURL(HttpServletRequest request)

Return the URL representing the scheme, server, and port number of the current request.

Field Detail

log

protected static Log log

Commons Logging instance.

Method Detail

absoluteURL

public static URL absoluteURL(HttpServletRequest request, 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.

Parameters: request The servlet request we are processing path The context-relative path (must start with '/')

Returns: absolute URL based on context-relative path

Throws: MalformedURLException if we cannot create an absolute URL

actionURL

public static String actionURL(HttpServletRequest request, ActionConfig action, String pattern)

Return the context-relative URL that corresponds to the specified {@link ActionConfig}, relative to the module associated with the current modules's {@link ModuleConfig}.

Parameters: request The servlet request we are processing action ActionConfig to be evaluated pattern URL pattern used to map the controller servlet

Returns: context-relative URL relative to the module

Since: Struts 1.1

applicationClass

public static Class applicationClass(String className)

Return the Class object for the specified fully qualified class name, from this web application's class loader.

Parameters: className Fully qualified class name to be loaded

Returns: Class object

Throws: ClassNotFoundException if the class cannot be found

applicationInstance

public static Object applicationInstance(String className)

Return a new instance of the specified fully qualified class name, after loading the class from this web application's class loader. The specified class MUST have a public zero-arguments constructor.

Parameters: className Fully qualified class name to use

Returns: new instance of class

Throws: ClassNotFoundException if the class cannot be found IllegalAccessException if the class or its constructor is not accessible InstantiationException if this class represents an abstract class, an interface, an array class, a primitive type, or void InstantiationException if this class has no zero-arguments constructor

canReuseActionForm

private static boolean canReuseActionForm(ActionForm instance, FormBeanConfig config)

Determine whether instance of ActionForm is suitable for re-use as an instance of the form described by config.

Parameters: instance an instance of ActionForm which was found, probably in either request or session scope. config the configuration for the ActionForm which is needed.

Returns: true if the instance found is "compatible" with the type required in the FormBeanConfig; false if not, or if instance is null.

Throws: ClassNotFoundException if the type property of config is not a valid Class name.

computeParameters

public static Map computeParameters(PageContext pageContext, String paramId, String paramName, String paramProperty, String paramScope, String name, String property, String scope, boolean transaction)

Deprecated: This will be removed after Struts 1.2. Use {@link org.apache.struts.taglib.TagUtils#computeParameters(PageContext,String,String,String,String,String,String,String,boolean)} instead.

Compute a set of query parameters that will be dynamically added to a generated URL. The returned Map is keyed by parameter name, and the values are either null (no value specified), a String (single value specified), or a String[] array (multiple values specified). Parameter names correspond to the corresponding attributes of the <html:link> tag. If no query parameters are identified, return null.

Parameters: pageContext PageContext we are operating in paramId Single-value request parameter name (if any) paramName Bean containing single-value parameter value paramProperty Property (of bean named by paramName containing single-value parameter value paramScope Scope containing bean named by paramName name Bean containing multi-value parameters Map (if any) property Property (of bean named by name containing multi-value parameters Map scope Scope containing bean named by name transaction Should we add our transaction control token?

Returns: Map of query parameters

Throws: JspException if we cannot look up the required beans JspException if a class cast exception occurs on a looked-up bean or property

computeURL

public static String computeURL(PageContext pageContext, String forward, String href, String page, Map params, String anchor, boolean redirect)

Deprecated: This will be removed after Struts 1.2 Use {@link RequestUtils#computeURL(PageContext, String, String, String, String, Map, String, boolean)} instead.

Compute a hyperlink URL based on the forward, href or page parameter that is not null.

Parameters: pageContext PageContext for the tag making this call forward Logical forward name for which to look up the context-relative URI (if specified) href URL to be utilized unmodified (if specified) page Module-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()?

Returns: URL with session identifier

Throws: MalformedURLException if a URL cannot be created for the specified parameters

computeURL

public static String computeURL(PageContext pageContext, String forward, String href, String page, String action, Map params, String anchor, boolean redirect)

Deprecated: This will be removed after Struts 1.2. Use {@link org.apache.struts.taglib.TagUtils#computeURL(PageContext,String,String,String,String,String,Map,String, boolean)} instead.

Compute a hyperlink URL based on the forward, href, action or page parameter that is not null. The returned URL will have already been passed to response.encodeURL() for adding a session identifier.

Parameters: pageContext PageContext for the tag making this call forward Logical forward name for which to look up the context-relative URI (if specified) href URL to be utilized unmodified (if specified) page Module-relative page for which a URL should be created (if specified) action Logical action name for which to look up the context-relative URI (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()?

Returns: URL with session identifier

Throws: MalformedURLException if a URL cannot be created for the specified parameters

computeURL

public static String computeURL(PageContext pageContext, String forward, String href, String page, String action, Map params, String anchor, boolean redirect, boolean encodeSeparator)

Deprecated: This will be removed after Struts 1.2. Use {@link org.apache.struts.taglib.TagUtils#computeURL(PageContext,String,String,String,String,String,Map,String,boolean,boolean)} instead.

Compute a hyperlink URL based on the forward, href, action or page parameter that is not null. The returned URL will have already been passed to response.encodeURL() for adding a session identifier.

Parameters: pageContext PageContext for the tag making this call forward Logical forward name for which to look up the context-relative URI (if specified) href URL to be utilized unmodified (if specified) page Module-relative page for which a URL should be created (if specified) action Logical action name for which to look up the context-relative URI (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()? encodeSeparator This is only checked if redirect is set to false (never encoded for a redirect). If true, query string parameter separators are encoded as >amp;, else & is used.

Returns: URL with session identifier

Throws: MalformedURLException if a URL cannot be created for the specified parameters

createActionForm

public static ActionForm createActionForm(HttpServletRequest request, ActionMapping mapping, ModuleConfig moduleConfig, ActionServlet servlet)

Create (if necessary) and return an ActionForm instance appropriate for this request. If no ActionForm instance is required, return null.

Parameters: request The servlet request we are processing mapping The action mapping for this request moduleConfig The configuration for this module servlet The action servlet

Returns: ActionForm instance associated with this request

createActionForm

public static ActionForm createActionForm(FormBeanConfig config, ActionServlet servlet)

Create and return an ActionForm instance appropriate to the information in config.

Does not perform any checks to see if an existing ActionForm exists which could be reused.

Parameters: config The configuration for the Form bean which is to be created. servlet The action servlet

Returns: ActionForm instance associated with this request

createServerStringBuffer

public static StringBuffer createServerStringBuffer(String scheme, String server, int port)

Return StringBuffer representing the scheme, server, and port number of the current request.

Parameters: scheme The scheme name to use server The server name to use port The port value to use

Returns: StringBuffer in the form scheme: server: port

Since: Struts 1.2.0

createServerUriStringBuffer

public static StringBuffer createServerUriStringBuffer(String scheme, String server, int port, String uri)

Return StringBuffer representing the scheme, server, and port number of the current request.

Parameters: scheme The scheme name to use server The server name to use port The port value to use uri The uri value to use

Returns: StringBuffer in the form scheme: server: port

Since: Struts 1.2.0

encodeURL

public static String encodeURL(String url)

Deprecated: Use {@link org.apache.struts.taglib.TagUtils#encodeURL(String)} instead. This will be removed after Struts 1.2.

Use the new URLEncoder.encode method from Java 1.4 if available, else use the old deprecated version. This method uses reflection to find the appropriate method; if the reflection operations throw exceptions, this will return the url encoded with the old URLEncoder.encode method.

Returns: String - the encoded url.

forwardURL

public static String forwardURL(HttpServletRequest request, ForwardConfig forward)

Return the context-relative URL that corresponds to the specified ForwardConfig. The URL is calculated based on the properties of the {@link ForwardConfig} instance as follows:

Parameters: request The servlet request we are processing forward ForwardConfig to be evaluated

Returns: context-relative URL

Since: Struts 1.1

forwardURL

public static String forwardURL(HttpServletRequest request, ForwardConfig forward, ModuleConfig moduleConfig)

Return the context-relative URL that corresponds to the specified ForwardConfig. The URL is calculated based on the properties of the {@link ForwardConfig} instance as follows:

Parameters: request The servlet request we are processing forward ForwardConfig to be evaluated moduleConfig Base forward on this module config.

Returns: context-relative URL

Since: Struts 1.2

getActionErrors

public static ActionErrors getActionErrors(PageContext pageContext, String paramName)

Deprecated: Use {@link org.apache.struts.taglib.TagUtils#getActionErrors(PageContext,String)} instead. This will be removed after Struts 1.2.

Retrieves the value from request scope and if it isn't already an ErrorMessages some classes are converted to one.

Parameters: pageContext The PageContext for the current page paramName Key for parameter value

Returns: ActionErrors from request scope

Throws: JspException

getActionMappingName

public static String getActionMappingName(String action)

Deprecated: This will be removed after Struts 1.2. Use {@link org.apache.struts.taglib.TagUtils#getActionMappingName(String)} instead.

Return the form action converted into an action mapping path. The value of the action property is manipulated as follows in computing the name of the requested mapping:

getActionMappingURL

public static String getActionMappingURL(String action, PageContext pageContext)

Deprecated: This will be removed after Struts 1.2. Use {@link org.apache.struts.taglib.TagUtils#getActionMappingURL(String,PageContext)} instead.

Return the form action converted into a server-relative URL.

getActionMessages

public static ActionMessages getActionMessages(PageContext pageContext, String paramName)

Deprecated: Use {@link org.apache.struts.taglib.TagUtils#getActionMessages(PageContext,String)} instead. This will be removed after Struts 1.2.

Retrieves the value from request scope and if it isn't already an ActionMessages some classes are converted to one.

Parameters: pageContext The PageContext for the current page paramName Key for parameter value

Returns: ActionErros in page context.

Throws: JspException

getAllParametersForMultipartRequest

private static Map getAllParametersForMultipartRequest(HttpServletRequest request, MultipartRequestHandler multipartHandler)

Create a Map containing all of the parameters supplied for a multipart request, keyed by parameter name. In addition to text and file elements from the multipart body, query string parameters are included as well.

Parameters: request The (wrapped) HTTP request whose parameters are to be added to the map. multipartHandler The multipart handler used to parse the request.

Returns: the map containing all parameters for this multipart request.

getModuleConfig

public static ModuleConfig getModuleConfig(HttpServletRequest request, ServletContext context)

Deprecated: Use {@link org.apache.struts.util.ModuleUtils#getModuleConfig(HttpServletRequest,ServletContext)} instead. This will be removed after Struts 1.2.

Return the ModuleConfig object is it exists, null otherwise.

Parameters: request The servlet request we are processing context The ServletContext for this web application

Returns: the ModuleConfig object

Since: Struts 1.1

getModuleConfig

public static ModuleConfig getModuleConfig(PageContext pageContext)

Deprecated: Use {@link org.apache.struts.taglib.TagUtils#getModuleConfig(PageContext)} instead. This will be removed after Struts 1.2.

Return the ModuleConfig object if it exists, null if otherwise.

Parameters: pageContext The page context.

Returns: the ModuleConfig object

Since: Struts 1.1

getModuleName

public static String getModuleName(HttpServletRequest request, ServletContext context)

Deprecated: Use Use {@link org.apache.struts.util.ModuleUtils#getModuleName(HttpServletRequest,ServletContext)} instead. This will be removed after Struts 1.2.

Get the module name to which the specified request belong.

Parameters: request The servlet request we are processing context The ServletContext for this web application

Returns: The module prefix or ""

getModuleName

public static String getModuleName(String matchPath, ServletContext context)

Deprecated: Use {@link org.apache.struts.util.ModuleUtils#getModuleName(String,ServletContext)} instead. This will be removed after Struts 1.2.

Get the module name to which the specified uri belong.

Parameters: matchPath The uri from which we want the module name. context The ServletContext for this web application

Returns: The module prefix or ""

getModulePrefixes

public static String[] getModulePrefixes(ServletContext context)

Deprecated: Use {@link org.apache.struts.util.ModuleUtils#getModulePrefixes(ServletContext)} instead. This will be removed after Struts 1.2.

Return the list of module prefixes that are defined for this web application. NOTE - the "" prefix for the default module is not included in this list.

Parameters: context The ServletContext for this web application.

Returns: An array of module prefixes.

Since: Struts 1.1

getMultipartHandler

private static MultipartRequestHandler getMultipartHandler(HttpServletRequest request)

Try to locate a multipart request handler for this request. First, look for a mapping-specific handler stored for us under an attribute. If one is not present, use the global multipart handler, if there is one.

Parameters: request The HTTP request for which the multipart handler should be found.

Returns: the multipart handler to use, or null if none is found.

Throws: ServletException if any exception is thrown while attempting to locate the multipart handler.

getRequestModuleConfig

public static ModuleConfig getRequestModuleConfig(HttpServletRequest request)

Deprecated: Use {@link org.apache.struts.util.ModuleUtils#getModuleConfig(HttpServletRequest)} instead. This will be removed after Struts 1.2.

Return the current ModuleConfig object stored in request, if it exists, null otherwise. This method can be used by a {@link org.apache.struts.action.PlugIn} to retrieve the current module config object. If no moduleConfig is found, this means that the request hasn't hit the server through the Struts servlet. The appropriate module config can be set and found with {@link RequestUtils#selectModule(HttpServletRequest, ServletContext)} .

Parameters: request The servlet request we are processing

Returns: the ModuleConfig object from request, or null if none is set in the request.

Since: Struts 1.1

getScope

public static int getScope(String scopeName)

Deprecated: This will be removed after Struts 1.2. Use {@link org.apache.struts.taglib.TagUtils#getScope(String)} instead.

Converts the scope name into its corresponding PageContext constant value.

Parameters: scopeName Can be "page", "request", "session", or "application" in any case

Returns: The constant representing the scope (ie. PageContext.REQUEST_SCOPE).

Throws: JspException if the scopeName is not a valid name.

Since: Struts 1.1

getUserLocale

public static Locale getUserLocale(HttpServletRequest request, String locale)

Look up and return current user locale, based on the specified parameters.

Parameters: request The request used to lookup the Locale locale Name of the session attribute for our user's Locale. If this is null, the default locale key is used for the lookup.

Returns: current user locale

Since: Struts 1.2

isXhtml

public static boolean isXhtml(PageContext pageContext)

Deprecated: Use {@link org.apache.struts.taglib.TagUtils#isXhtml(PageContext)} instead. This will be removed after Struts 1.2.

Returns true if the custom tags are in XHTML mode.

Since: Struts 1.1

lookup

public static Object lookup(PageContext pageContext, String name, String scopeName)

Deprecated: This will be removed after Struts 1.2. Use {@link org.apache.struts.taglib.TagUtils#lookup(PageContext,String,String)} instead.

Locate and return the specified bean, from an optionally specified scope, in the specified page context. If no such bean is found, return null instead. If an exception is thrown, it will have already been saved via a call to saveException.

Parameters: pageContext Page context to be searched name Name of the bean to be retrieved scopeName Scope to be searched (page, request, session, application) or null to use findAttribute() instead

Returns: JavaBean in the specified page context

Throws: JspException if an invalid scope name is requested

lookup

public static Object lookup(PageContext pageContext, String name, String property, String scope)

Deprecated: This will be removed after Struts 1.2. Use {@link org.apache.struts.taglib.TagUtils#lookup(PageContext,String,String,String)} instead.

Locate and return the specified property of the specified bean, from an optionally specified scope, in the specified page context. If an exception is thrown, it will have already been saved via a call to saveException.

Parameters: pageContext Page context to be searched name Name of the bean to be retrieved property Name of the property to be retrieved, or null to retrieve the bean itself scope Scope to be searched (page, request, session, application) or null to use findAttribute() instead

Returns: property of specified JavaBean

Throws: JspException if an invalid scope name is requested JspException if the specified bean is not found JspException if accessing this property causes an IllegalAccessException, IllegalArgumentException, InvocationTargetException, or NoSuchMethodException

lookupActionForm

private static ActionForm lookupActionForm(HttpServletRequest request, String attribute, String scope)

message

public static String message(PageContext pageContext, String bundle, String locale, String key)

Deprecated: Use {@link org.apache.struts.taglib.TagUtils#message(PageContext,String,String,String)} instead. This will be removed after Struts 1.2.

Look up and return a message string, based on the specified parameters.

Parameters: pageContext The PageContext associated with this request bundle Name of the servlet context attribute for our message resources bundle locale Name of the session attribute for our user's Locale key Message key to be looked up and returned

Returns: message string

Throws: JspException if a lookup error occurs (will have been saved in the request already)

message

public static String message(PageContext pageContext, String bundle, String locale, String key, Object[] args)

Deprecated: Use {@link org.apache.struts.taglib.TagUtils#message(PageContext,String,String,String,Object[])} instead. This will be removed after Struts 1.2.

Look up and return a message string, based on the specified parameters.

Parameters: pageContext The PageContext associated with this request bundle Name of the servlet context attribute for our message resources bundle locale Name of the session attribute for our user's Locale key Message key to be looked up and returned args Replacement parameters for this message

Returns: message string

Throws: JspException if a lookup error occurs (will have been saved in the request already)

pageURL

public static String pageURL(HttpServletRequest request, String page)

Deprecated: Use {@link org.apache.struts.taglib.TagUtils#pageURL(HttpServletRequest request, String page, ModuleConfig moduleConfig)} instead. This will be removed after Struts 1.2.

Return the context-relative URL that corresponds to the specified page attribute value, calculated based on the pagePattern property of the current module's {@link ModuleConfig}.

Parameters: request The servlet request we are processing page The module-relative URL to be substituted in to the pagePattern pattern for the current module (MUST start with a slash)

Returns: context-relative URL

Since: Struts 1.1

populate

public static void populate(Object bean, 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. Suitable conversion is done for argument types as described under convert().

Parameters: bean The JavaBean whose properties are to be set request The HTTP request whose parameters are to be used to populate bean properties

Throws: ServletException if an exception is thrown while setting property values

populate

public static void populate(Object bean, String prefix, String suffix, 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. Suitable conversion is done for argument types as described under 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

Parameters: bean The JavaBean whose properties are to be set prefix The prefix (if any) to be prepend to bean property names when looking for matching parameters suffix The suffix (if any) to be appended to bean property names when looking for matching parameters request The HTTP request whose parameters are to be used to populate bean properties

Throws: ServletException if an exception is thrown while setting property values

present

public static boolean present(PageContext pageContext, String bundle, String locale, String key)

Deprecated: Use {@link org.apache.struts.taglib.TagUtils#present(PageContext ,String,String,String)} instead. This will be removed after Struts 1.2.

Return true if a message string for the specified message key is present for the specified Locale.

Parameters: pageContext The PageContext associated with this request bundle Name of the servlet context attribute for our message resources bundle locale Name of the session attribute for our user's Locale key Message key to be looked up and returned

Returns: true if a message string for message key exists

Throws: JspException if a lookup error occurs (will have been saved in the request already)

printableURL

public static String printableURL(URL url)

Compute the printable representation of a URL, leaving off the scheme/host/port part if no host is specified. This will typically be the case for URLs that were originally created from relative or context-relative URIs.

Parameters: url URL to render in a printable representation

Returns: printable representation of a URL

requestToServerStringBuffer

public static StringBuffer requestToServerStringBuffer(HttpServletRequest request)

Return StringBuffer representing the scheme, server, and port number of the current request. Server-relative URLs can be created by simply appending the server-relative path (starting with '/') to this.

Parameters: request The servlet request we are processing

Returns: URL representing the scheme, server, and port number of the current request

Since: Struts 1.2.0

requestToServerUriStringBuffer

public static StringBuffer requestToServerUriStringBuffer(HttpServletRequest request)

Return the string representing the scheme, server, and port number of the current request. Server-relative URLs can be created by simply appending the server-relative path (starting with '/') to this.

Parameters: request The servlet request we are processing

Returns: URL representing the scheme, server, and port number of the current request

Since: Struts 1.2.0

requestURL

public static URL requestURL(HttpServletRequest request)

Return the URL representing the current request. This is equivalent to HttpServletRequest.getRequestURL in Servlet 2.3.

Parameters: request The servlet request we are processing

Returns: URL representing the current request

Throws: MalformedURLException if a URL cannot be created

retrieveUserLocale

public static Locale retrieveUserLocale(PageContext pageContext, String locale)

Deprecated: This will be removed after Struts 1.2. Use {@link org.apache.struts.taglib.TagUtils#getUserLocale(PageContext,String)} instead.

Look up and return current user locale, based on the specified parameters.

Parameters: pageContext The PageContext associated with this request locale Name of the session attribute for our user's Locale. If this is null, the default locale key is used for the lookup.

Returns: current user locale

saveException

public static void saveException(PageContext pageContext, Throwable exception)

Deprecated: Use {@link org.apache.struts.taglib.TagUtils#saveException(PageContext,Throwable)} instead. This will be removed after Struts 1.2.

Save the specified exception as a request attribute for later use.

Parameters: pageContext The PageContext for the current page exception The exception to be saved

selectModule

public static void selectModule(String prefix, HttpServletRequest request, ServletContext context)

Deprecated: Use {@link org.apache.struts.util.ModuleUtils#selectModule(String,HttpServletRequest,ServletContext)} instead. This will be removed after Struts 1.2.

Select the module to which the specified request belongs, and add corresponding request attributes to this request.

Parameters: prefix The module prefix of the desired module request The servlet request we are processing context The ServletContext for this web application

Since: Struts 1.1

selectModule

public static void selectModule(HttpServletRequest request, ServletContext context)

Deprecated: Use {@link org.apache.struts.util.ModuleUtils#selectModule(HttpServletRequest,ServletContext)} instead. This will be removed after Struts 1.2.

Select the module to which the specified request belongs, and add corresponding request attributes to this request.

Parameters: request The servlet request we are processing context The ServletContext for this web application

serverURL

public static URL serverURL(HttpServletRequest request)

Return the URL representing the scheme, server, and port number of the current request. Server-relative URLs can be created by simply appending the server-relative path (starting with '/') to this.

Parameters: request The servlet request we are processing

Returns: URL representing the scheme, server, and port number of the current request

Throws: MalformedURLException if a URL cannot be created

Copyright B) 2000-2007 - The Apache Software Foundation