• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

character encoding problem

 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ketan Khairnar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Kia Phia Ben
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Pradip Bhat
Add one line in servlet
request.setCharacterEncoding("utf-8");
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Kia Phia Ben:
Hi Pradip Bhat
Add one line in servlet
request.setCharacterEncoding("utf-8");


I have tried that, it did not work. I dont know why it did not work.
 
Ketan Khairnar
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
have you read what I have written here before?
that should work.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.



Yes.. this is first line of code.
 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you go to http://7bee.j2ee.us/ChatHouse/chat/ and enter to Atic room? Then you can try to enter Japanese text and URLs and tell if you can see them correctly back.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There was some problem with Tomcat installation. I installed Tomcat again and everything is working fine.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic