Character Set problems in Tomcat 5.x --
There are three areas to be set: 1. Client 2. Tomcat 3. Server
1. The encoding format must be set for the client request. Assume that the HTTP program is used to automatically request data. The sample code is as follows:
Encode the request data using urlencoder for UTF-8 and then write it to the requested data stream using WR
Private Static inputstream httprequest (string Surl, map ATTR) throws ioexception {
String data = "";
Inputstream is = NULL;
If (ATTR! = NULL ){
Iterator it = ATTR. keyset (). iterator ();
While (it. hasnext ()){
String key = (string) it. Next ();
Data + = "&" + urlencoder. encode (key, "UTF-8") + "=" + urlencoder. encode (string) ATTR. get (key), "UTF-8 ");
}
// Send data
URL url = new URL (Surl );
Urlconnection conn = URL. openconnection ();
Conn. setdooutput (true );
Outputstreamwriter wR = new outputstreamwriter (conn. getoutputstream ());
Wr. Write (data. substring (1 ));
Wr. Flush ();
Is = conn. getinputstream ();
} Else {
URL url = new URL (Surl );
Urlconnection conn = URL. openconnection ();
Conn. Connect ();
Is = conn. getinputstream ();
}
Return is;
}
JSP should have the following content:
<% @ Page contenttype = "text/html;Charset = UTF-8"%>
2. Set a certain ctor in Tomcat.
In server. XML, confirm that the encoding format is set.
<ConnectorUriencoding = "UTF-8"Acceptcount = "100" connectiontimeout = "20000" disableuploadtimeout = "true" Port = "80" redirectport = "8443">
</Connector>
3. You need to set the encoding format for the server segment program. For example, you can write
Public void Service (servletrequest request, servletresponse resp)
Throws servletexception, ioexception {
Request. setcharacterencoding ("UTF-8");
Of course, server segments generally use filters to do this, so that you do not need to set the encoding format in each servlet, and you can use parameters to determine what encoding format to use.