User Tools

Site Tools


glassfish_uri_parameter_encoding

Glassfish URI Parameter Encoding

Quoting the Glassfish Wiki:

How can I specify the encoding of HTTP request parameters? GlassFish treats the encoding of a request's URI separately from the encoding of its parameters. In the case of a GET request, query parameters are appended to the URI (separated by ?), whereas in the case of a POST request, they are carried inside the request body.

The two types of encoding are specified in different places:

  • The URI encoding may be specified as the value of a property named uriEncoding of the <http-listener> element in domain.xml. This encoding, which defaults to UTF-8, is applied to any request URI received by the corresponding HTTP listener.
  • The request parameter encoding, on the other hand, defaults to ISO-8859-1 and may be overridden in one of two places: Either programmatically inside a servlet, by calling the ServletRequest's setCharacterEncoding method, or declaratively, by specifying the parameter encoding as the value of the default-charset attribute of the <parameter-encoding> element in sun-web.xml, as shown in the following example, which sets the request's parameter encoding to UTF-8:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app 
  PUBLIC "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 8.0 Servlet 2.4//EN"
 "http://www.sun.com/software/sunone/appserver/dtds/sun-web-app_2_4-0.dtd">
 
<sun-web-app>
  <locale-charset-info default-locale="">
    ...
    <parameter-encoding default-charset="UTF-8"/>
    ...
  </locale-charset-info>
</sun-web-app>

or in the glassfish-web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app 
  PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN"
  "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
    ...
    <parameter-encoding default-charset="UTF-8" />
    ...
</glassfish-web-app>

https://wikis.oracle.com/display/GlassFish/FaqHttpRequestParameterEncoding

glassfish_uri_parameter_encoding.txt · Last modified: 2014/03/06 08:47 by mihael