开发者

encoding issues with XHTML in JSP Page

开发者 https://www.devze.com 2022-12-15 02:37 出处:网络
I am using the following in my jsp page <% response.setContentType(\"application/xhtml+xml\"); %>

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.

0

精彩评论

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