Google app engine 不';Google Appengine云是否支持JSP/servlet响应中的unicode字符?
我正在向部署在Google Appengine服务器上的应用程序发出请求。应用程序返回一个unicode格式的响应。如果我通过developmentserver访问,它会像我预期的那样很好,但是当我部署到googleproductionappengine服务器上时,所有这些都是一个问号,如下所示 “标题”:������������������������" 如果您查看servlet的源代码,我确保以下内容已经就绪Google app engine 不';Google Appengine云是否支持JSP/servlet响应中的unicode字符?,google-app-engine,jsp,servlets,Google App Engine,Jsp,Servlets,我正在向部署在Google Appengine服务器上的应用程序发出请求。应用程序返回一个unicode格式的响应。如果我通过developmentserver访问,它会像我预期的那样很好,但是当我部署到googleproductionappengine服务器上时,所有这些都是一个问号,如下所示 “标题”:������������������������" 如果您查看servlet的源代码,我确保以下内容已经就绪 response.setCharacterEncoding("UTF-8"); r
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");
请提供帮助。我刚刚尝试从JSP页面返回UTF-8字符,它们似乎呈现正确。在JSP中,我有
和head
。没有设置任何内容类型或编码来响应Servlet
我还尝试在本地和部署的数据存储中检索和存储UTF-8数据,并在这两种情况下正确呈现所有UTF-8字符
下面是Servlet:
@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;
}
}
@覆盖
受保护的void doPost(HttpServletRequest-req、HttpServletResponse-resp)
抛出IOException{
datastoreService.put(新示例((字符串)req.getParameter(“字段”))
.getEntity());
分别以“/”号填列;
}
@凌驾
受保护的void doGet(最终HttpServletRequest请求,最终HttpServletResponse响应)抛出ServletException,IOException{
final RequestDispatcher RequestDispatcher=getServletContext().getRequestDispatcher(“/WEB-INF/jsp/list.jsp”);
最终迭代器示例=Iterators.transform(
datastoreService.prepare(新查询(例如.class.getSimpleName()).asIterator(),
新函数(){
@凌驾
公共示例应用(最终实体输入){
返回新示例(输入);
}
});
请求setAttribute(“示例”,示例);
转发(req,resp);
}
公共静态类示例{
私人最终实体;
公共示例(最终字符串字段){
实体=新实体(例如.class.getSimpleName());
实体。设置属性(“字段”,字段);
}
公共示例(实体){
this.entity=实体;
}
公共字符串getField(){
返回(字符串)entity.getProperty(“字段”);
}
公共实体getEntity(){
返回实体;
}
}
和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>
例子
例子
-
我也遇到了这个问题——jsp中的某些unicode字符(例如→) 在开发服务器上呈现良好,但在appengine中部署时不会。即使html头部包含
解决办法是增加
<%@page pageEncoding="UTF-8"%>
HTTP响应头本身包含什么?(Firebug:Net>HTML)。浏览器说什么?(Firefox:View>Character Encoding)以下是原始响应:HTTP/1.1 200 OK内容类型:text/html;charset=utf-8内容编码:gzip日期:2011年2月3日星期四11:59:55 GMT服务器:Google前端缓存控制:private,x-gzip-OK=”"内容长度:问题文本是直接来自JSP还是直接来自java代码,还是间接来自表单输入?如果是来自表单输入,我以前见过这种情况,并且问题可能在处理库中很深——尝试将表单转换为多部分编码。此响应直接来自Servlet。我已经实际上在数据存储中存储了一些数据。我通过servlet获取这些数据。然后,在GWT上传输/部署后,包含这些字符的源文件本身就损坏了,或者它们是使用错误的编码加载/读取的。因为我不使用GWT,所以我无法给出更具体的解决方法。嗨,感谢您的响应。那么什么时候我键入了.println(“一些unicode文本”)它实际上是有效的。当我在数据存储中存储一些unicode数据时,当我直接存储unicode数据时,它是有效的,但当我存储从网站获取的unicode数据并将其存储在数据存储中时,我不认为它存储在unicode中。即使我使用unicode编码将字符串读取为字节,它也不起作用,它仍然不会将其存储为unicode数据上述问题仅存在于appengine google服务器的生产中。但在本地计算机中,它的工作方式与我预期的一样。我尝试在数据存储中存储和检索数据,UTF-8字符显示正确。请参阅上面我的更新答案。