wood burning stoves*
The moose likes JSP and the fly likes setting utf-8 in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "setting utf-8 in jsp" Watch "setting utf-8 in jsp" New topic
Author

setting utf-8 in jsp

D kukreja
Ranch Hand

Joined: Jan 29, 2008
Posts: 39
Hi,

I have set the charset to utf-8 using following <%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=UTF-8" %>
When I see the encoding in the "view" option of browser it shows utf-8 correctly ..but the multi lingual characters like chinese ones ..are shown as "???" in the screen.
Also i m using struts 2.0 , and as per struts site I tried setting it in the form level like this :
<form action="XXXXXXX" method="post" accept-charset="utf-8">
This didn't help , I tried putting a hidden parameter by name "charset" and set it to utf-8 ..as suggested in struts site as well.
please provide any suggestions here ..
thanks
Stevi Deter
Ranch Hand

Joined: Mar 22, 2008
Posts: 265

How are you saving the jsp file with the double-byte characters?

If you're not actually saving the file with UTF-8 encoding, you will sometimes see the behavior you're describing.


There will always be people who are ahead of the curve, and people who are behind the curve. But knowledge moves the curve. --Bill James
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41884
    
  63
Are the characters themselves UTF-8 encoded? Is a font available that includes these Chinese characters?


Ping & DNS - my free Android networking tools app
D kukreja
Ranch Hand

Joined: Jan 29, 2008
Posts: 39
yes , the characters are correct ..chinese font is also available.
setting DBCS while creating the jsp ? I didn't understand what do you mean by that.
K.Suresh Kumar
Ranch Hand

Joined: Nov 21, 2007
Posts: 41
Hi,
Do you have Chinese font in your machine ?. Just you open a chines language based website for testing purpose. Now you see the characters like "???" then you must install chines font in your machine.

Regards,
Suresh Kumar.K
Stevi Deter
Ranch Hand

Joined: Mar 22, 2008
Posts: 265

The default character encoding for many programs is ANSI (for example, most MS Windows products from Notepad to Word), not UTF-8 or Unicode.

If you save the file with the incorrect encoding, the characters will not be shown correctly when you try to use UTF-8 encoding.

I have occasionally found this to be the cause of apparent encoding issues at a later stage in the process - the file looks OK in the original editing software, but as soon as the file is read by another program, the mismatch in encoding causes problems.

So check what your character encoding is for the file you're saving to verify if this is or is not the case.
D kukreja
Ranch Hand

Joined: Jan 29, 2008
Posts: 39
I am saving the values in the DB2 columns. The column is saved as "漢字" , and is rendered as it is on the screen.
DB2 supports utf-8 already. So I need to set the encoding while posting the form ?
I have used <form> tag to set the encoding , as suggested in struts site.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: setting utf-8 in jsp