JSPページからUTF-8文字を返そうとしましたが、正しく表示されているようです。 JSPで私は<jsp:directive.page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" />
と頭の中に<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
を持っています。サーブレットのコンテンツタイプやエンコーディングをレスポンスに設定しない。
また、データストアとの間でUTF-8データの取得と格納をローカルおよびデプロイしてみました。両方の場合ですべてのUTF-8文字が正しくレンダリングされました。ここで
は、サーブレットの:
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
datastoreService.put(new Example((String) req.getParameter("field"))
.getEntity());
resp.sendRedirect("/");
}
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
final RequestDispatcher requestDispatcher = getServletContext().getRequestDispatcher("/WEB-INF/jsp/list.jsp");
final Iterator<Example> examples = Iterators.transform(
datastoreService.prepare(new Query(Example.class.getSimpleName())).asIterator(),
new Function<Entity, Example>() {
@Override
public Example apply(final Entity input) {
return new Example(input);
}
});
req.setAttribute("examples", examples);
requestDispatcher.forward(req, resp);
}
public static class Example {
private final Entity entity;
public Example(final String field) {
entity = new Entity(Example.class.getSimpleName());
entity.setProperty("field", field);
}
public Example(Entity entity) {
this.entity = entity;
}
public String getField() {
return (String) entity.getProperty("field");
}
public Entity getEntity() {
return entity;
}
}
とJSP:
<jsp:directive.page contentType="text/html;charset=UTF-8"
language="java" isELIgnored="false" />
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
version="-//W3C//DTD XHTML 1.1//EN" xml:lang="en" xmlns:og="http://opengraphprotocol.org/schema/">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Examples</title>
</head>
<body>
<h1>Examples</h1>
<form action="/" method="post">
<div>
<input type="text" name="field" />
<input type="submit" value="Submit" />
</div>
</form>
<ul>
<c:forEach var="example" items="${examples}">
<li>
<p><c:out value="${example.field}" /></p>
</li>
</c:forEach>
</ul>
</body>
</html>
HTTP応答ヘッダー自体には何が含まれていますか? (Firebug:* Net> HTML *)。ブラウザは何を言いますか? (Firefox:*表示>文字エンコーディング*) – BalusC
以下は生の応答です:HTTP/1.1 200 OK Content-Type:text/html; charset = utf-8 コンテンツエンコーディング:gzip 日付:2011年2月3日11:59:55 GMT サーバー:Googleフロントエンド キャッシュコントロール:プライベート、x-gzip-ok = "" コンテンツの長さ: 288 – Antony
問題のテキストはJSPから直接来るのか、直接Javaコードから来るのですか、それともフォーム入力から間接的に来ていますか?フォーム入力からのものであれば、これまでに見たことがあり、問題は処理ライブラリの深いところにある可能性があります。フォームをマルチパートエンコーディングに切り替えてみてください。 –