2

I am building my app in Google App Engine

Ok, here I got a Servlet

public void doPost(HttpServletRequest req, HttpServletResponse resp)
        throws IOException {
     String firstName=req.getParameter("firstName");
     System.out.println(URLDecoder.decode(firstName, "UTF-8")+" "+ firstName);
  }

Now, I sent "Thủy" to the Servlet and it shows this output

th?y th?y

Then, I set up appengine-web.xml

<appengine-web-app>.......
 <env-variables>
    <env-var name="DEFAULT_ENCODING" value="UTF-8" />
  </env-variables>

</appengine-web-app>

Then when running i got this error:

com.google.appengine.tools.development.EnvironmentVariableChecker$IncorrectEnvironmentVariableException: One or more environment variables have been configured in appengine-web.xml that have missing or different values in your local environment. We recommend you use system properties instead, but if you are interacting with legacy code that requires specific environment variables to have specific values, please set these environment variables in your environment before running.
[Mismatch environmentVariableName=DEFAULT_ENCODING environmentVariableValue=null appEngineWebXmlValue=UTF-8 appEngineWebXmlFile=C:\Users\henry\workspace8\FluentEnglish\war\WEB-INF\appengine-web.xml]
    at com.google.appengine.tools.development.EnvironmentVariableChecker.check(EnvironmentVariableChecker.java:75)
    at com.google.appengine.tools.development.ApplicationConfigurationManager.checkEnvironmentVariables(ApplicationConfigurationManager.java:240)
    at com.google.appengine.tools.development.ApplicationConfigurationManager.access$000(ApplicationConfigurationManager.java:32)
    at com.google.appengine.tools.development.ApplicationConfigurationManager$WarModuleConfigurationHandle.checkEnvironmentVariables(ApplicationConfigurationManager.java:394)
    at com.google.appengine.tools.development.JettyContainerService.connectContainer(JettyContainerService.java:211)
    at com.google.appengine.tools.development.AbstractContainerService.createConnection(AbstractContainerService.java:273)
    at com.google.appengine.tools.development.AbstractInstanceHolder.createConnection(AbstractInstanceHolder.java:37)
    at com.google.appengine.tools.development.AbstractModule.createConnection(AbstractModule.java:73)

So, what's wrong?

Why doesn't HttpServletRequest show Unicode Text?

How to make HttpServletRequest show Unicode Text?

0

1 Answer 1

1

The last error message is caused by the appengine-web.xml config, see this thread for more.

You don´t specify how you do the POST, but the following example succeeds with your handler (without the DEFAULT_ENCODING appengine-web config):

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<form method="post" action="/api/test">
  <input type="text" name="firstName" value="Thủy"><br>
  <input type="submit"  name="OK">
</form>

while this fails (missing content type from the sender):

<form method="post" action="/api/test">
  <input type="text" name="firstName" value="Thủy"><br>
  <input type="submit"  name="OK">
</form>
Sign up to request clarification or add additional context in comments.

3 Comments

I got "<%@ page contentType="text/html;charset=UTF-8" language="java" %>" but it still doesn't work
If you look at the outgoing request in the browser´s inspector; how are the data encoded?
I checked the real data in Google app engine web site and it ok. But somehow the “Datastore Viewer” of “Development Console” of “Google App Engine” does not show correctly

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.