简体   繁体   中英

How to configure content type and content encoding using glassfish server?

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 files 在此处输入图片说明 .

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

Those strange characters you are seeing is the UTF-8 Byte Order Mark . They are a special set of bytes that indicate how a document is encoded. Unfortunately, when interpreted as ISO-8859-1 , you wind up with the problem you have. There are two ways to resolve this.

The first way is to change the output character set to UTF-8. I believe this can be done in your server configuration, in your web.xml configuration , or by setting the character set on the HTTP request object in code; for example: yourServletRequest.setCharacterEncoding("UTF-8");

The second way is to remove the BOM from your Javascript files. You can do this by opening them in Notepad++ , going to Encoding > Convert to ANSI , and then saving them. Alternatively, open them in Notepad, then go to Save As and ensure that the Encoding option is set to ANSI before saving them. Note that this may cause issues if you have non- ISO-8859-1 text in your Javascript files, although this is unlikely.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM