This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes Struts character encoding Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Struts character encoding" Watch "Struts character encoding" New topic
Author

Struts character encoding

Oliver Moore
Ranch Hand

Joined: Mar 04, 2003
Posts: 44
Hi All,

I'm using struts 1.1 as part of my web application, but I've hit some major character encoding issues! Why does struts automatically encode all of the strings placed directly into a given form bean as ISO-8859-1?

I've set all my JSPs to UTF-8 encoding, but the � symbol still renders incorrectly as �� if I look at the contents of my form bean. I can get out of this by doing the following

but this is a pain to do for all strings. I guess I could put a method to do this conversion in all of my entity beans, but this issue seems so fundamental that I feel I'm missing something.

Is this normal behaviour for struts, or is there a setting I require?

My reason for using UTF-8 encoding is that the � symbol seems to be rendered incorrectly by my JSPs (be it dynamic content or hard coded in the page) as �� when I use ISO-8859-1.

Any suggestions as to either solve the struts conversion problem, or how to render � correctly with ISO-8859-1 would be much appreciated.

Regards,

Ols


Regards,<p>Ols
sreenath reddy
Ranch Hand

Joined: Sep 21, 2003
Posts: 415
HI

Yah i agree that encoding is a big pain..............but i will tellu one way is u just want to display them in jsps correctly u can use
<meta http-equiv="Content-Type" content="text/html; charset=urencoding what u need">

u need to place this in all the jsps whereever u need to dipslya that characters.........this will force the browsers endoing to the encoding u need.................

but i will tell if u want to read some files from the file systemw hich are stored with diff language then u need to go for encoing using jaba.lang.string ......and encode it to whatever u need


Help onencoding is very less if u get something u tell me i struggled like anything for this
Oliver Moore
Ranch Hand

Joined: Mar 04, 2003
Posts: 44
Hi All,

I believe the issue I was experiencing was that all strings passed back to the server were assumed to be in ISO format, despite the page encoding being set to utf-8. As I now understand it, many browsers do not correctly support passing the encoding type of a response back to the server.

After much messing about with request/response setContentType(), <%@ page contentType="text/html; charset=utf-8" %> and modifying the Struts-config file I was having very little success until I found that there is an encoding filter included in Tomcat 5 (\jakarta-tomcat-5.0.19\webapps\servlets-examples\WEB-INF\classes\filters\SetCharacterEncodingFilter.java).

Implementing this has solved all my issues and everything seems to be carried as utf-8 now. Seeing as this corrected my issue, I assume the root cause was that the contentType of the request object was not being set correctly at some point in the application.

I've attached a few useful links below on the subject of encoding. Any comments on my fix or a definite cause of my issue would be appreciated.

Common problems with i18n and servlets/jsp-s
Tomcat User-list
Struts Guide
indmango siri
Greenhorn

Joined: Jun 30, 2011
Posts: 4
This helped me resolve my issue with character encoding .
Thanks a lot
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Struts character encoding
 
Similar Threads
Encoding norwegian characters as UTF-8
Converting from ISO-8859-1 to UTF-8
JSF and Character Sets (UTF-8 mainly)
string delimiter
character encodings in streamReaders/Writers