0

I am building a web application using JSF and Spring in eclipse indigo using Glassfish server 3.1.2 . Everything is going great but it is showing me this error in firebug in 2 JavaScript filesenter image description here.

When I check in those files I didn't find any illegal character in those files but firebug still showing this.
I have used these files in one of ASP.Net project and they didn't mess there so i checked and matched their content type from both projects then I found that in ASP.Net project these files have

Content-Type = application/x-javascript

And in my JSP-Spring(JAVA) project there

Content-Type = text/javascript;charset=ISO-8859-1

is this.So you can see that sames files have changed their content scheme. I found that this scheme can be change by configuration in glassfish server.So I want to change my JS files content-Type to same as in ASP type.
If anyone have any other solution then please share because I haven't found any solution other than changing the scheme from glassfish server
Thanks

4

1 回答 1

1

您看到的那些奇怪字符是 UTF-8 Byte Order Mark。它们是一组特殊的字节,指示文档的编码方式。不幸的是,当解释为ISO-8859-1时,您最终会遇到问题。有两种方法可以解决这个问题。

第一种方法是将输出字符集更改为 UTF-8。我相信这可以在您的服务器配置中、在您的web.xml 配置中或通过在代码中设置 HTTP 请求对象上的字符集来完成;例如:yourServletRequest.setCharacterEncoding("UTF-8");

第二种方法是从 Javascript 文件中删除BOM 。您可以通过在Notepad++中打开它们,转到Encoding > Convert to ANSI,然后保存它们来做到这一点。或者,在记事本中打开它们,然后转到另存为并确保在保存它们之前将编码选项设置为 ANSI。请注意,如果您的 Javascript 文件中有非ISO-8859-1文本,这可能会导致问题,尽管这不太可能。

于 2012-09-06T20:37:22.913 回答