Я только что попытался вернуть символы UTF-8 со страницы JSP, и они, кажется, отображаются правильно.В 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>