Oracle JavaServer Pages Developer's Guide and Reference Release 8.1.7 Part Number A83726-01 |
|
Character encoding of request parameters is not well defined in the HTTP specification. Most servlet containers must interpret them using the servlet default encoding, ISO-8859-1
.
For such environments, where the servlet container cannot encode multibyte request parameters and bean property settings, OracleJSP offers extended support through the translate_params
configuration parameter.
It is also possible to use equivalent code in the JSP page, which is necessary in the Oracle Servlet Environment.
Important:
Do not enable the
|
Set translate_params
to true
to override servlet containers that cannot encode multibyte request parameters and bean property settings. (For information about how to set OracleJSP configuration parameters, see "OracleJSP Configuration Parameter Settings".)
When this flag is enabled, OracleJSP encodes the request parameters and bean property settings based on the character set of the response
object, as indicated by the response.getCharacterEncoding()
method.
The translate_params
flag affects parameter names and values, specifically:
getParameter()
method output
getParameterValues()
method output
getParameterNames()
method output
jsp:setProperty
settings for bean property values
The translate_params
configuration parameter, being a runtime parameter, cannot be set in the Oracle Servlet Engine environment. (Translation-time configuration can be set for the OSE environment through ojspc
command-line options. There is no equivalent for runtime parameters.)
For this reason, and possibly other reasons as well, it is useful to be aware of equivalent functionality that can be implemented through scriptlet code in the JSP page, for example:
<%@ page contentType="text/html; charset=EUC-JP" %> ... String paramName="XXYYZZ"; // where XXYYZZ is a multibyte string paramName = new String(paramName.getBytes(response.getCharacterEncoding()), "ISO8859_1"); String paramValue = request.getParameter(paramName); paramValue= new String(paramValue.getBytes("ISO8859_1"), "EUC-JP"); ...
This code accomplishes the following:
XXYYZZ
as the parameter name to search for. (Presume XX
, YY
, and ZZ
are three Japanese characters.)
ISO-8859-1
, the servlet container character set, so that the servlet container can interpret it. (First a byte array is created for the parameter name, using the character encoding of the request object.)
ISO-8859-1
encoding.)
EUC-JP
for further processing or output to the browser.
See the next two sections for an NLS sample that depends on translate_params
being enabled, and an NLS sample that contains the equivalent code so that it does not depend on the translate_params
setting.
The following sample accepts a user name in Japanese characters and correctly outputs the name back to the browser. In a servlet environment that cannot encode multibyte request parameters, this sample depends on the OracleJSP configuration setting of translate_params=true
.
Presume XXYY
is the parameter name (something equivalent to "user name" in Japanese) and AABB
is the default value (also in Japanese).
(See the next section for a sample that has the code equivalent of the translate_params
functionality, and so does not depend on the translate_params
setting.)
<%@ page contentType="text/html; charset=EUC-JP" %> <HTML> <HEAD> <TITLE>Hello</TITLE></HEAD> <BODY> <% //charset is as specified in page directive (EUC-JP) String charset = response.getCharacterEncoding(); %> <BR> encoding = <%= charset %> <BR> <% String paramValue = request.getParameter("XXYY"); if (paramValue == null || paramValue.length() == 0) { %> <FORM METHOD="GET"> Please input your name: <INPUT TYPE="TEXT" NAME="XXYY" value="AABB" size=20> <BR> <INPUT TYPE="SUBMIT"> </FORM> <% } else { %> <H1> Hello, <%= paramValue %> </H1> <% } %> </BODY> </HTML>
Following is the sample input:
and the sample output:
The following sample, as with the preceding sample, accepts a user name in Japanese characters and correctly outputs the name back to the browser. This sample, however, has the code equivalent of translate_params
functionality, so does not depend on the translate_params
setting.
Presume XXYY
is the parameter name (something equivalent to "user name" in Japanese) and AABB
is the default value (also in Japanese).
For an explanation of the critical code in this sample, see "Code Equivalent to the translate_params Configuration Parameter".
<%@ page contentType="text/html; charset=EUC-JP" %> <HTML> <HEAD> <TITLE>Hello</TITLE></HEAD> <BODY> <% //charset is as specified in page directive (EUC-JP) String charset = response.getCharacterEncoding(); %> <BR> encoding = <%= charset %> <BR> <% String paramName = "XXYY"; paramName = new String(paramName.getBytes(charset), "ISO8859_1"); String paramValue = request.getParameter(paramName); if (paramValue == null || paramValue.length() == 0) { %> <FORM METHOD="GET"> Please input your name: <INPUT TYPE="TEXT" NAME="XXYY" value="AABB" size=20> <BR> <INPUT TYPE="SUBMIT"> </FORM> <% } else { paramValue= new String(paramValue.getBytes("ISO8859_1"), "EUC-JP"); %> <H1> Hello, <%= paramValue %> </H1> <% } %> </BODY> </HTML>
|
Copyright © 1996-2000, Oracle Corporation. All Rights Reserved. |
|