开发者

Doesn't Google Appengine Cloud support unicode characters in response from JSP/Servlets?

I am making a request to my application de开发者_如何学编程ployed on to Google Appengine server. The application returns a response which is in unicode. The response if I access through development server, it comes nicely as I expected it, but when I deployed on to Google production appengine server, it all comes a question marks as following "header":"������������������������"

if you look at the source of servlet, I ensured that following is already in place

response.setCharacterEncoding("UTF-8");
response.setContentType("text/html; charset=UTF-8");

Please help.


I just tried returning UTF-8 characters from a JSP page and they seem to render correctly. In the JSP I have <jsp:directive.page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" /> and in head <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />. Not setting anything about content type or encoding to response in the Servlet.

I also tried retrieving and storing UTF-8 data to and from the datastore both locally and deployed and it renders all the UTF-8 characters properly on both occasions.

Here's the 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;
  }
}

And the 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>


I was having this problem as well -- certain unicode characters in my jsp (such as →) rendered fine with the development server, but not when deployed in appengine. This even though the html head contained .

The solution was to add

    <%@page pageEncoding="UTF-8"%>

to the top of the jsp file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜