Eclipse javascript character encoding

Posted by Bardock on Stack Overflow See other posts from Stack Overflow or by Bardock
Published on 2010-05-19T18:24:03Z Indexed on 2010/05/19 18:30 UTC
Read the original article Hit count: 205

Filed under:
|
|

Hi,

I'd like to display some language specific characters from javascript but I can't.

My app is a Java webapp and the front end is jQuery. All the characters that are sended from the server - in a JSP or with AJAX - are displayed properly. When I want to display some text hardcoded in to the javascript file it's broken.

I'm using Eclipse. In the JSP's header I use:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

I've tried this (charset in the script element) too:

<script type="text/javascript" charset="utf-8"><c:import url="/JS/mainJS.js" /></script>

In my Eclipse I've set the project properties / text file encoding to UTF-8 AND I've checked the JS files' resource properties / text file encoding that is UTF-8 too.

But when I try this:

$.test = function(){
    var s = "éééáááuuuu";
    alert(s);
}

I get:

éééáááűűűű

The strange thing is that: When I try in a separate html file (in the same project), It's working:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>
  <head>
    <title>Test</title>

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

    <style type="text/css">
        body {background: #c0c0c0;}
    </style>

    <script type="text/javascript">
        $(document).ready(function(){
            var s = "éááuuúúú";
            $("#console").text(s);
            alert(s);
        })
    </script>

  </head>

  <body>
        <div id="console"></div>
  </body>
</html>

Even if I DO NOT use any content type and page encoding settings.

What is the problem? What shall I do? (I'm using Apache Tomcat integrated in Eclipse)

Thanks in advance!

© Stack Overflow or respective owner

Related posts about character-encoding

Related posts about jQuery