【发布时间】:2010-07-23 11:31:25
【问题描述】:
我目前正在尝试在 WebLogic 应用服务器上部署一些 RSS 提要。提要的视图是 .jspx 文件,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom"
xmlns:georss="http://www.georss.org/georss"
xmlns:jsp="http://java.sun.com/JSP/Page"
xmlns:c="http://java.sun.com/jsp/jstl/core"
xmlns:fmt="http://java.sun.com/jsp/jstl/fmt"
xmlns:fn="http://java.sun.com/jsp/jstl/functions"
xmlns:util="http://example.com/util">
<jsp:directive.page pageEncoding="utf-8" contentType="application/xhtml+xml" />
<jsp:useBean id="now" class="java.util.Date" scope="page" />
[...]
<c:forEach var="category" items="${categories}">
<entry>
<title>${util:htmlEscape(category.label)}</title>
<id>${category.id}</id>
<c:if test="${empty parentId}">
<link href="${util:htmlEscape(fullRequest)}?parentId=${category.id}" />
</c:if>
<summary>${util:htmlEscape(category.localizedLabel)}</summary>
</entry>
</c:forEach>
</feed>
问题在于,在我的本地开发服务器 (Apache Tomcat 6.0) 上一切正常,但在 WebLogic 服务器上,所有 UTF-8 字符都被弄乱了。
在 Firefox 中,我看到类似 <summary>Formaci�n</summary> 的内容。奇怪字符的字节序列是ef bf bd,我似乎在我正在进行的测试中应该收到的所有 UTF-8 字符(á,ó,í)都得到了这个。我已经检查了 firebug 中的内容类型和编码,看起来没问题(Content-Type: application/xhtml+xml; charset=UTF-8)。
在 Chrome 中,第一次出现奇怪字符时内容会被截断,并显示错误消息:This page contains the following errors: error on line 1 at column 523: Encoding error。
我不确定发生了什么,但考虑到在我的本地 Tomcat 上一切正常,我认为这与 Web 服务器正在执行的操作有关。欢迎任何想法。
谢谢,
亚历克斯
【问题讨论】:
-
util:htmlEscape()到底在做什么?没错,它正在转义 HTML,但我想知道您为什么不为此使用 JSTL 提供的fn:escapeXml()。这可能是编码问题的根本原因。顺便说一句,xml 命名空间中有一个错字..hputilvsutil。 -
我是 Java/jsp(x) 的新手,我没有找到用于转义的库函数,所以我自己写了:)。我会用你建议的替换它,但我很确定我的功能不是问题。我尝试完全不调用它,但 UTF-8 字符仍然被损坏。
标签: java unicode character-encoding weblogic jspx