2015-03-25 92 views
1

我正在將舊的和一些新的東西合併到一個Web應用程序中。但是,使用瑞典語字母時,頁面將失敗。它似乎不是一個服務器問題,因爲舊的.jsp頁面將正確加載。具有特殊字符的Facelets頁面導致MalformedByteSequenceException:UTF8Reader.invalidByte中的3字節UTF-8序列的無效字節2

我在xhtml頭文件中丟失了什麼?舊頁的

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> 
......... 
+1

你的編輯器不保存使用UTF-8的Facelets文件。答案取決於所使用的編輯器。你最好告訴它。在不相關的說明中,爲什麼您將元內容類型標頭從UTF-8更改爲ISO-8859-1?當通過HTTP提供服務時,這不會造成麻煩,但這很簡單。 – BalusC 2015-03-25 10:59:38

+0

我在windows上使用eclipse – user2130951 2015-03-25 11:23:59

+0

將此更改爲UTF-8使其正常工作。 user2130951 2015-03-25 11:33:33

回答

3

Facelets的默認使用UTF-8編碼(作爲World Domination一部分)。您應該將所有編輯器和圖層配置爲使用UTF-8。

你的具體情況,有至少有兩個可能的原因:

  1. Eclipse應當通過窗口>首選項>常規>工作空間>文本文件編碼被配置爲使用UTF-8來保存文件。

    enter image description here

  2. 的HTTP/HTML Content-Type頭應指定charset=UTF-8,正如你在你的JSP您由於某種原因改爲傳統的ISO-8859-1編碼了。

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

實際上從一開始就沒有內容類型我以爲它會默認爲UTF-8 – user2130951 2015-03-25 12:49:05

相關問題