开发者

JSP output encoding

When I write the following

é

or even

<%=new String(new byte[]{(byte) 0xC3, (byte) 0xA9}, "UTF-8")%>

I get a string with the length of 1. It contains a single UTF-8 character C3A9 or é.

But when it gets written to the browser, the browser cannot decode it unless I use latin1. So that means it is getting encoded and written as western even though in the top of the JSP I have

<%@page import="..." contentType="text/html" pageEncoding="UTF-8" session="false"%>

How can I get the JSP to output UTF-8 instead of writing a UTF-8 header and then encoding with latin1? 开发者_如何学Go"Western (ISO-8859-1)"


You should only use pageEncoding, and write the symbol itself, rather then referring to it by its code.

Also make sure your .jsp file is also encoded in UTF-8. Your IDE should handle the pageEncoding attribute and set the encoding appropriately, but with particular settings or if not using an IDE, the .jsp can still be encoded in ISO-8859-1. Change that to UTF-8

Finally, make sure your response is really using UTF-8 as encoding (use firebug for example). If not, try setting it response.setCharacterEncoding(..)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜