user2130951
user2130951

Reputation: 2741

Facelets page with special characters causes MalformedByteSequenceException: Invalid byte 2 of 3-byte UTF-8 sequence at UTF8Reader.invalidByte

I am merging an old and some new stuff into a webapplication. However when using swedish letters the page will fail. It does not seem to be a server issues since the old .jsp pages will load correctly.

What am I missing in the 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>

Example of old page that will work

<%@ 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>
.........

Upvotes: 2

Views: 2263

Answers (1)

BalusC
BalusC

Reputation: 1109874

Facelets uses by default UTF-8 encoding (as part of World Domination). You should be configuring all editors and layers to use UTF-8.

In your particular case, there are at least two probable causes:

  1. Eclipse should via Window > Preferences > General > Workspace > Text File Encoding be configured to use UTF-8 to save files.

    enter image description here

  2. The HTTP/HTML Content-Type header should be specifying charset=UTF-8, exactly as you had in your JSP which you for some reason changed to the legacy ISO-8859-1 encoding.

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

Upvotes: 4

Related Questions