eclipse - 包含特殊字符的 Facelets 页面会导致 MalformedByteSequenceException : Invalid byte 2 of 3-byte UTF-8 sequence at UTF8Reader. invalidByte

标签 eclipse jsf character-encoding facelets

我正在将旧的和一些新的东西合并到一个网络应用程序中。但是,当使用瑞典字母时,页面将失败。这似乎不是服务器问题,因为旧的 .jsp 页面将正确加载。

我在 xhtml header 中缺少什么?

mar 25, 2015 11:50:53 FM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [Faces Servlet] in context with path [/BowlingInfo] threw exception
com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 3-byte UTF-8 sequence.
    at com.sun.org.apache.xerces.internal.impl.io.UTF8Reader.invalidByte(UTF8Reader.java:691)

<!DOCTYPE html>
<html lang="sv-SE" 
    xmlns="http://www.w3c.org/1999/xhtml"
    xmlns:h="http://xmlns.jcp.org/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:p="http://primefaces.org/ui"
    xmlns:c="http://java.sun.com/jsp/jstl/core">
<h:head>
    <link rel="stylesheet" href="bowling-style.css" />
    <meta http-equiv="content-type" content="text/html" charset="ISO-8859-1" />
</h:head>
<h:body>
    <!-- FAIL -->
    <h1>Hallmästaren</h1>
</h:body>
</html>

可以使用的旧页面示例

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="f"  uri="http://java.sun.com/jsf/core"%>
<%@ taglib prefix="h"  uri="http://java.sun.com/jsf/html"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Svalövs bowlinghall</title>
<script type="text/JavaScript">
        <!--
        var currentTime = new Date()
        function AutoRefresh( t ) {
                setTimeout("location.reload(true);", t);
        }
        function GetServerDate() {
                var date = new Date();
                dateNow = date;
                document.write(dateNow);
                return dateNow;
        }
        </script>
        <link rel="stylesheet" type="text/css" href="bowling-style.css" />  
</head>
<body onload="JavaScript:AutoRefresh(15000);" bgcolor="C2F2BD">
<f:view>
.........

最佳答案

Facelets 默认使用 UTF-8 编码(作为 World Domination 的一部分)。您应该将所有编辑器和图层配置为使用 UTF-8。

在您的具体情况下,至少有两个可能的原因:

  1. Eclipse 应通过窗口 > 首选项 > 常规 > 工作区 > 文本文件编码 配置为使用 UTF-8 保存文件。

    enter image description here

  2. HTTP/HTML Content-Type header 应指定 charset=UTF-8,与您在 JSP 中由于某种原因更改的内容完全相同到旧版 ISO-8859-1 编码。

    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
    

关于eclipse - 包含特殊字符的 Facelets 页面会导致 MalformedByteSequenceException : Invalid byte 2 of 3-byte UTF-8 sequence at UTF8Reader. invalidByte,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29253705/

相关文章:

c++ - 使用 Visual Studio 2012 构建 Eclipse C++ Docfrac 项目

javascript - 避免关闭模态对话框 bootstrap 和 jsf

Java 应用程序因特殊字符而失败

ruby-on-rails - 如何在 Rails 3 中强制对 HTML 电子邮件进行字符编码?

java - Git 管理环境特定配置

java - RCP 导出的 EXE 显示 java 控制台

Eclipse Indigo 远程系统资源管理器 : FTP Connection

jsf - 如何添加具有多个源 mp3 的媒体播放器

jsf - primefaces 订单列表未根据更改的订单进行更新

MySQL。无法将俄语字符插入类型为 VARCHAR(45) 的列