I have a servlet running on Tomcat 5.5.7 container on windows Japanese OS. The servlet receives a HTTP POST request with its URL UTF-8 encoded. I am not able to read the characters properly(i am getting junk) even though I have URIEncoding="UTF-8 in conf\server.xml file. I tried to setting req.setCharacterEncoding("UTF-8") but it does not work.I am going mad.
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 from 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. You must call the method or tag before parsing any request parameters or reading any input from the request. Calling the method or tag once data has been read will not affect the encoding.
Response Encoding This is required to get multilingual data on UI side of our application. The setCharacterEncoding, setContentType, and setLocale methods can be called repeatedly to change the character encoding. Calls made after the servlet response�s getWriter method has been called or after the response is committed have no effect on the character encoding. Data is sent to the response stream on buffer flushes (for buffered pages) or on encountering the first content on unbuffered pages. Calls to setContentType set the character encoding only if the given content type string provides a value for the charset attribute. Calls to setLocale set the character encoding only if neither setCharacterEncoding nor setContentType has set the character encoding before. For Java Servlets, you can specify a page encoding in the HTTP header by calling the setContentType() method of the Servlet API. The following doGet() function shows how this method should be called.
Hope this helps. Just check where u made mistake. and Let us know
Tough in space?, <a href="http://tjws.sf.net" target="_blank" rel="nofollow">Get J2EE servlet container under 150Kbytes here</a><br />Love your iPod and want it anywhere?<a href="http://mediachest.sf.net" target="_blank" rel="nofollow">Check it here.</a><br /><a href="http://7bee.j2ee.us/book/Generics%20in%20JDK%201.5.html" target="_blank" rel="nofollow">Curious about generic in Java?</a><br /><a href="http://7bee.j2ee.us/bee/index-bee.html" target="_blank" rel="nofollow">Hate ant? Use bee.</a><br /><a href="http://7bee.j2ee.us/addressbook/" target="_blank" rel="nofollow">Need contacts anywhere?</a><br /><a href="http://searchdir.sourceforge.net/" target="_blank" rel="nofollow">How to promote your business with a search engine</a>
Sorry guys. It was not a problem with Tomcat. Previously I was running Tomcat as Windows service with JRE version 1.5.0_05. Later I used startup.bat for ruuning Tomcat which was using a JDK v 1.5.0_1 and it worked fine. Looks like there is some bug with JRE 1.5.0_05. I started Tomcat as a windows service with the latest JRE version 1.5.0_06 and it is working fine. Thanks guys.