2016-01-15 18 views
2

我建立我的應用程序在谷歌應用程序引擎如何在Google應用引擎中設置Unicode?

好了,在這裏我得到了一個Servlet

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

現在,我送「翠」的Servlet,它顯示了這個輸出

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> 

然後運行時,我得到這個錯誤:

 
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) 

所以,有什麼不對?

爲什麼HttpServletRequest不顯示Unicode文本?

如何讓HttpServletRequest顯示Unicode文本?

回答

1

最後的錯誤信息是由appengine-web.xml配置引起的,更多信息請參閱this thread

您鴕鳥政策指定你是怎麼做的職位,但下面的例子與你的處理器成功(沒有DEFAULT_ENCODING AppEngine上的web配置):

<%@ 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> 

而失敗從發送方(遺漏的內容類型):

<form method="post" action="/api/test"> 
    <input type="text" name="firstName" value="Thủy"><br> 
    <input type="submit" name="OK"> 
</form> 
+0

我 「** <%@頁面的contentType =」 text/html的;字符集= UTF-8" LANGUAGE = 「java的」 %> **」,但它仍然無法正常工作 – Tom

+0

如果您在瀏覽器的檢查員中查看傳出的請求;數據如何編碼? – stoffen

+0

我檢查了Google應用程序引擎網站上的真實數據,它確定。但不知何故,「Google App Engine」的「開發控制檯」的「數據存儲查看器」無法正確顯示 – Tom

相關問題