一個關於 Web 應用國際化的問題

iceant發表於2003-09-03
我從 Sun 的WebService 教材中看到以下這段話:
Ref:http://java.sun.com/webservices/docs/1.2/tutorial/doc/index.html

但是我覺得很奇怪,Server 端怎麼才知道 Client 使用的 Charset 是什麼呢?
雖然我們可以透過 accept-language Header 知道使用者的語言偏好,但是這不能說明使用者提交時使用的是相應的 Encoding 啊,如果不能判斷使用者提交時用的 Encoding 是什麼,那這個 setRequestEncoding 的用處就不大了?

Request Encoding
The request encoding is the character encoding in which parameters in an incoming request are interpreted. Currently, many browsers do not send a request encoding qualifier with the Content-Type header. In such cases, a Web container will use the default encoding--ISO-8859-1--to parse request data.

If the client hasn't set character encoding and the request data is encoded with a different encoding than the default, the data won't be interpreted correctly. To remedy this situation, you can use the ServletRequest.setCharacterEncoding(String enc) method to override the character encoding supplied by the container. This method must be called prior to reading request parameters or reading input using getReader. To control the request encoding from JSP pages, you can use the JSTL fmt:requestEncoding tag.

This method must be called prior to parsing any request parameters or reading any input from the request. Calling this method once data has been read will not affect the encoding.

相關文章