views:

275

answers:

2

Hi Guys,

I am using utf-8 in my jsp page. I have set the page pageEncoding="UTF-8" contentType="text/html;"

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

But when i try to alert a UTF-8 value then its coming as same utf-8 characters.

A: 

But is the DATA on the page UTF-8 too? If you set the page to UTF-8 but load data which is for example Windows 1256, you will not see Arabic at all

If your issue is alert('Something Arabic here') you may want to use entities

Here is a good explanation http://www.w3.org/International/tutorials/bidi-xhtml/

Here is a few methods (perhaps not THE methods):

alert(document.getElementBzId('hiddenDiv').innerHTML)

where you have

<div id="hiddenDiv" style="display:none">&#1575;&#1587;&#1578;&#1605;&#1575;&#1585;&#1577; &#1591;&#1604;&#1576; &#1578;&#1608;&#1592;&#1610;&#1601;</div>

the other one is creating it dynamically

<script>
var alertString = "&#1575;&#1587;&#1578;&#1605;&#1575;&#1585;&#1577;&#1591;&#1604;&#1576; &#1578;&#1608;&#1592;&#1610;&#1601;" 
var d = document.createElement('div');
d.innerHTML=alertString;
alert(d.innerHTML)
</script>
mplungjan
Yes the data in the page is arabic. for example<div align="center" class="heading_ar">استمارة طلب توظيف</div>but if i alert('arabic in utf-8') its not working.if i use the alert('arabic text') its getting alerted as question marks.
vishnu
Please have a look at my amended answer
mplungjan
A: 

If the page is properly encoded UTF-8 then my first guess is that the HTTP headers are indicating something other than UTF-8. HTTP headers override <meta http-equiv, read HTML 4.01 here.

Check in a browser the exact HTTP response headers. If there is an inappropriate Content-Type header, change it. If there is none, add one.

fsb