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 JSP and the fly likes Encoding question 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 » Java » JSP
Bookmark "Encoding question" Watch "Encoding question" New topic
Author

Encoding question

Bhushan Jawle
Ranch Hand

Joined: Nov 22, 2001
Posts: 249
I am trying to display data from database (Shift_JIS format) on a JSP. The data being displayed is garbage as encoding of page is Western European, fair enough.
If I change the encoding of page by <@page > directive of main page(which includes other jsps) to shift_jis, the encoding is set properly but data is still garbage.
If I display data by not setting encoding of main.jsp to shift_jis, it takes default encoding as Western European and displays garbage as mentioned earlier, however, if I change the encoding of browser to Shift_JIS (by browser menu)the data is displayed correctly. I am a bit confused as how is browser menu setting encoding different from setting it in JSP.
The data being displayed if from a session scoped bean which is populated by servlet.
I am not sure about where does the problem lie(I tried reconstructing string in bean by specifying str.getBytes(), "SJIS") but didn't work.
Regards,
Bhushan
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Have you tried getting the jsp to define the encoding and set the browser to "Auto-Select" the encoding rather than specifying anything?
Dave
Bhushan Jawle
Ranch Hand

Joined: Nov 22, 2001
Posts: 249
Sorry I forgot to mention that I have tried setting browser to auto-select.
In case I specify the setting in main.jsp it does select proper encoding when the composite page is displayed, however data displayed in corrupt, but when I don't specify the encoding, get the data and change page encoding by right click on page the data is displayed correctly, I wonder whether this has got something to do with the timing as theoritically both should have same effect.
Thanks for youy suggestion anyway David.
Regards,
Bhushan
Bhushan Jawle
Ranch Hand

Joined: Nov 22, 2001
Posts: 249
I just found out soln. to my problem. The string was getting corrupted in XML parser, so by reconstructing string there as new String(stringBeingUsed.getBytes(), "Shift_JIS") solved the problem
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Encoding question
 
Similar Threads
Unable to read the Japanese character from HTTP Response
Prioblem displaying Japanese characters in IE using WebSphere 5.1
Character Encoding
Character Encoding
page encoding