This section describes the methods to be used for character code conversion between the browser and application, and the notes on the implementation of the JSPs and JavaScript.
Use the method of the HttpServletRequest class to obtain the query string and POST data sent using the browser. From among the methods of the HttpServletRequest class, the methods related to character code conversion and the notes on usage are as follows:
With this method, you set the character code used in the message body of the request, and in the parameters sent with the GET request query. This method must be executed before the input stream is read by using the getParameter method and the getReader method.
(a) setCharacterEncoding method
With this method, you set the character code used in the message body of the request, and in the parameters sent with the GET request query. This method must be executed before the input stream is read by using the getParameter method and the getReader method.
The following table describes the range in which the character code set up with the setCharacterEncoding method is used.
Table A-3 Range in which the character code set up with the setCharacterEncoding method is used
Method | Data sent from the HTML form (including queries) | Message body other than that described at the left |
---|---|---|
getParameter | A | -- |
getParameterNames | A | -- |
getParameterValues | A | -- |
getParameterMap | A | -- |
getInputStream | C | C |
getReader | C | B |
getQueryString | C | -- |
With this method, you specify the parameter name and obtain the value of the parameter included in the request. The obtained value is URL-decoded and converted to Unicode. Before you obtain the parameter name and parameter value, you must specify the character code by using the setCharacterEncoding method. If the character code is not specified, Unicode conversion is performed assuming ISO-8859-1. The same applies to the getParameterNames method, getParameterValues method, and getParameterMap method of the HttpServletRequest class.
With this method, you obtain the stream for reading the binary data included in the message body of the request. The encoded string is obtained as is from the data sent from the HTML form; therefore, the obtained string must be decoded using an appropriate character code.
With this method, you use the BufferedReader class in the message body of the request and extract the data as the character data. The character data is converted to the same character code as the message body. The encoded string is obtained as is from the data sent from the HTML form; therefore, the obtained string must be decoded using an appropriate character code.
This method returns the query string included behind the requested URL path. The encoded string is obtained as is from the data sent from the HTML form; therefore, the obtained string must be decoded using an appropriate character code.
To include a file using the include directive of the JSP file, use the contentType attribute to specify the encoding in the JSP file that forms the include source. Also, specify the character code for the JSP file in the pageEncoding attribute. If the character code is not specified, the include destination characters might not be displayed normally.