|
Page Edited :
SLINGxSITE :
Request Parameters
Request Parameters has been edited by Mike Mueller (Nov 25, 2008). Change summary: Fix for Sling API and correct hidden field charset. This page is now up to date. Request Parameter Handling in SlingServlet APIThe Servlet API specification provides the following methods to access the parameters of a request
As a special restriction only two kinds of parameters are supported: (1) Query String parameters and (2) parameters contained in the request data of content type application/x-www-form-encoded. That is file uploads using request data of type multipart/form-data are not directly supported by the servlet specification. Finally the actual encoding of the parameters is all but safe because the encoding of URLs is not very well defined and browsers do not set the character encoding when sending post data. Fortunately, they use the same character encoding for sending back form content as was used by the server to send the form. Sling APITo overcome these restrictions and to provide uniform access to request parameters the Sling API in addition to the Servlet API methods to access parameters provides an abstraction of parameters which is applicable to all parameters sent by clients, the RequestParameter interface. Through this interface, each parameter may be analyzed for these topics:
To accomodate this new interface as well as to provide easy access in the traditional way the SlingHttpServletRequest interface adds following methods to the standard Servlet API parameter access methods:
All parameters are handled the same, that is all methods give access to the same parameters regardless of whether the parameters were transmitted in the request query, as part of form encoded data or as part of a multipart/form-data request. Character EncodingTraditionally, the encoding of parameters, especially in text area input forms, has been a big issue. To solve this issue Sling introduces the following convention:
The first rule is essential as it helps decoding the form input correctly. The second rule is not actually a very hard requirement but to enable support for all (or most) character sets used, using UTF-8 is one of the best choices anyway. When Sling is now receiving a request and is asked for the parameters, the parameters are parsed in two phases: The first phase just parses the raw input data using an identity transformation of bytes to characters. This identity transformation happens to generate strings as the original data was generated with ISO-8859-1 encoding. The second phase locates the _charset_ parameter and fixes the character encodings of the parameters as follows:
|
Unsubscribe or edit your notifications preferences
