2012-07-06 166 views
3

我正在嘗試編寫一個簡單的Google App Engine應用程序。我正在學習本教程: https://developers.google.com/appengine/docs/java/gettingstarted/creating,但是我無法使其工作。Google App Engine HTTP錯誤403

當本地主機上測試,我得到:

HTTP ERROR 403 
Problem accessing /. Reason: 
    FORBIDDEN 
Powered by Jetty:// 

這是我的應用程序代碼:

package test; 

import java.io.IOException; 
import javax.servlet.http.*; 

public class Test extends HttpServlet { 
    private static final long serialVersionUID = 1L; 

    public void doGet(HttpServletRequest req, HttpServletResponse resp) 
      throws IOException { 
     resp.setContentType("text/plain"); 
     resp.getWriter().println("Hello, world"); 
    } 
} 

我的web.xml文件:

<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE web-app PUBLIC 
"-//Oracle Corporation//DTD Web Application 2.3//EN" 
"http://java.sun.com/dtd/web-app_2_3.dtd"> 

<web-app xmlns="http://java.sun.com/xml/ns/javaee" version="2.5"> 
    <servlet> 
     <servlet-name>test</servlet-name> 
     <servlet-class>test.Test</servlet-class> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>test</servlet-name> 
     <url-pattern>/test</url-pattern> 
    </servlet-mapping> 
    <welcome-file-list> 
     <welcome-file>index.html</welcome-file> 
    </welcome-file-list> 
</web-app> 

我的AppEngine上的Web .xml文件:

<?xml version="1.0" encoding="utf-8"?> 
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0"> 
    <application>halocline-test</application> 
    <version>10</version> 

    <!-- 
    Allows App Engine to send multiple requests to one instance in parallel: 
    --> 
    <threadsafe>true</threadsafe> 

    <!-- Configure java.util.logging --> 
    <system-properties> 
    <property name="java.util.logging.config.file" value="WEB-INF/logging.properties"/> 
    </system-properties> 

    <!-- 
    HTTP Sessions are disabled by default. To enable HTTP sessions specify: 

     <sessions-enabled>true</sessions-enabled> 

    It's possible to reduce request latency by configuring your application to 
    asynchronously write HTTP session data to the datastore: 

     <async-session-persistence enabled="true" /> 

    With this feature enabled, there is a very small chance your app will see 
    stale session data. For details, see 
    http://code.google.com/appengine/docs/java/config/appconfig.html#Enabling_Sessions 
    --> 

</appengine-web-app> 

控制檯輸出:

Jul 06, 2012 2:42:34 PM com.google.apphosting.utils.jetty.JettyLogger info 
INFO: Logging to JettyLogger(null) via com.google.apphosting.utils.jetty.JettyLogger 
Jul 06, 2012 2:42:35 PM com.google.apphosting.utils.config.AppEngineWebXmlReader readAppEngineWebXml 
INFO: Successfully processed C:\Users\Halocline\workspace\Test\war\WEB-INF/appengine-web.xml 
Jul 06, 2012 2:42:35 PM com.google.apphosting.utils.config.AbstractConfigXmlReader readConfigXml 
INFO: Successfully processed C:\Users\Halocline\workspace\Test\war\WEB-INF/web.xml 
Jul 06, 2012 3:42:36 PM com.google.appengine.tools.development.DevAppServerImpl start 
INFO: The server is running at http://localhost:8888/ 
Jul 06, 2012 3:42:36 PM com.google.appengine.tools.development.DevAppServerImpl start 
INFO: The admin console is running at http://localhost:8888/_ah/admin 

沒有錯誤顯示在控制檯當我打開本地主機:在我的網頁瀏覽器8888。

任何想法我做錯了什麼?

回答

1

你的servlet映射到http://localhost:8888/test

+0

非常感謝,有效。但是,當我部署此應用程序並訪問MyAppID.appspot.com/test時,出現以下錯誤: 錯誤:服務器錯誤 服務器遇到錯誤,無法完成請求。 如果問題仍然存在,請報告您的問題並提及此錯誤消息以及導致該問題的查詢。 – 2012-07-06 17:57:02

+0

查看appengine上的日誌文件。 – 2012-07-06 18:52:36

+0

@Jaroslaw Pawlak:查看管理控制檯中的日誌文件 – 2012-07-06 20:26:04

0

我相信你可能在一個錯誤的目錄中的index.html文件。檢查它沒有意外滑入WEB-INF。它應該直接在war之下。