encoding issues with XHTML in JSP Page
I am using the following in my jsp page
<% response.setContentType("application/xhtml+xml"); %>
and the page renders properly except that some characters do not render correctly, for example the "copyright" character/symbol.
However, if I use:
<% response.setContentType("application/xhtml+xml;charset=UTF开发者_开发技巧-8"); %>
Internet explorer renders the page as XML document (xml tree displayed) but the good thing is that all characters are resolved and displayed correctly.
Can anyone shed some light on this?
Thanks.
Here's an article which explains the phenomenon "Unicode" in perspective of Java webapps: Unicode - How to get the characters right?
That said, I strongly recommend you not to use scriptlets in JSP. Just use the following:
<%@ page pageEncoding="UTF-8" %>
<!DOCTYPE whatever XHTML doctype you're using here>
<html xmlns="whatever XHTML namespace you're using here">
<head>
<meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8" />
...
That ought to be enough.
精彩评论