相关疑难解决方法(0)

特殊字符'\ u0098'使用charCodeAt()读作'\ u02dc'

我正在从Java创建test.js,如下所示.Test.js实现函数d(),它接收参数特殊字符〜('\ u0098');

函数d()应显示此特殊字符的charCodeAt(),即152.但是,它显示732.

请注意,字符152和732均由特殊字符〜表示,如下所示.

http://www.fileformat.info/info/unicode/char/098/index.htm

http://www.fileformat.info/info/unicode/char/2dc/index.htm

如何强制功能d()显示152而不是732?(charset问题?).谢谢

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();
}
Run Code Online (Sandbox Code Playgroud)

TEST.JS由TEST.JAVA创建

function d(a)
{
  a=(a+"").split("");
  alert(a[0].charCodeAt(0));
};
d("˜"); // Note special character representing '\u0098'
Run Code Online (Sandbox Code Playgroud)

的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>
Run Code Online (Sandbox Code Playgroud)

javascript unicode servlets iso-8859-1 character-encoding

2
推荐指数
1
解决办法
1486
查看次数