简体   繁体   中英

Html special characters and Javascript

I'm using javascript and ajax framework into client side and Java glassfish into server side.

I'm trying to send a mail with this text:

"àèìòù !"£$%&/()=?^"

but when I read my post request (into java server side) I have this result:

"à èìòù !"£$%&/()=?^"

I need to convert all html special characters into respective html code, for example:

& -> &
à -> à 

How can I do? Thare are some javascript libraries that performs this operation?

Welcome to one of the most stupid decisions ever. The servlet spec defines that the default encoding should be ISO-8859-1 (instead of UTF-8).

So, in order for your java application to read those characters properly after a POST, you need to set up a Servlet Filter that forcers the charset to be UTF-8. This happens because most (if not all) browsers use UTF-8 as the default charset and don't set the Accept-Charset header.

This is such a common thing, that tomcat bundles one of these filters( How do I change how POST parameters are interpreted? ). If you're planning to deploy to different servlet containers, I suggest you to write your own filter (just copy paste the one from tomcat).

Yes! there is methods available for this, one example would to be the replace(); method. more information here

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