I am creating test.js from Java, as per below. Test.js implements function d(), that receives as parameter special character ˜ ('\u0098');
Function d() should display the charCodeAt() of this special characters, that would be 152. However, it displays 732.
Please note that characters 152 and 732 are both represented by special character ˜, as per below.
http://www.fileformat.info/info/unicode/char/098/index.htm
http://www.fileformat.info/info/unicode/char/2dc/index.htm
How can I force function d() to display 152 instead of 732? (charset issue?). THANKS
TEST.JAVA
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setHeader("Content-Type", "text/javascript;charset=ISO-8859-1");
res.setHeader("Content-Disposition","attachment;filename=test.js");
res.setCharacterEncoding("ISO-8859-1");
PrintWriter printer=res.getWriter();
printer.write("function d(a){a=(a+\"\").split(\"\");alert(a[0].charCodeAt(0));};d(\""); // Writes beginning of d() function
printer.write('\u0098'); // Writes special character as parameter of d()
printer.write("\");"); // Writes end of d() function
printer.close();
}
TEST.JS created by TEST.JAVA
function d(a)
{
a=(a+"").split("");
alert(a[0].charCodeAt(0));
};
d("˜"); // Note special character representing '\u0098'
TEST.HTML
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
<body>
<script type="text/javascript" charset="ISO-8859-1" src="test.js"></script>
</body>
</html>