1

我目前正在尝试在 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 上一切正常。欢迎任何想法。

谢谢,
亚历克斯

4

2 回答 2

2

The issue was coming from the order of the attributes in the jspx directive and the fact that I wasn't including the charset in the contentType attribute!

After switching:

<jsp:directive.page pageEncoding="utf-8" contentType="application/xhtml+xml" />

to:

<jsp:directive.page contentType="application/xhtml+xml; charset=UTF-8" 
     pageEncoding="UTF-8" />

The characters came out fine. I fiddled around a bit more, and, curiously, found out that this:

<jsp:directive.page pageEncoding="UTF-8"
      contentType="application/xhtml+xml; charset=UTF-8" />

doesn't work. I don't really understand why, but I'm guessing that it's a bug in WebLogic. The version I deployed on was 10.0.

于 2010-07-28T10:02:44.067 回答
1
于 2010-07-23T15:08:07.750 回答