4

我有一个 GAE/J 程序(带有 JSP),它在开发服务器上完美运行,但是当我将它部署到 App Engine 时,它​​返回:

错误:服务器错误

服务器遇到错误,无法完成您的请求。如果问题仍然存在,请报告您的问题并提及此错误消息和导致它的查询。

我使用 Ecpise 来部署我的程序。我的环境和设置:

赢 7 x64

Eclipse 版本:Juno Service Release 2 Build id:20130225-0426

JRE 系统库 [jdk1.7.0_21]

应用引擎 SDK 1.7.7

在 App Engine 管理控制台日志中显示一个“警告”:

Failed startup of context com.google.apphosting.utils.jetty.RuntimeAppEngineWebAppContext@1c24a0b{/,/base/data/home/apps/s~4562545625ab/1.366972147789894265}
java.lang.IllegalStateException: No forced path servlet for /WEB-INF/home.jsp
    at org.mortbay.jetty.servlet.ServletHandler.initialize(ServletHandler.java:679)
    at org.mortbay.jetty.servlet.Context.startContext(Context.java:140)
    at org.mortbay.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1250)
    at org.mortbay.jetty.handler.ContextHandler.doStart(ContextHandler.java:517)
    at org.mortbay.jetty.webapp.WebAppContext.doStart(WebAppContext.java:467)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.createHandler(AppVersionHandlerMap.java:219)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.getHandler(AppVersionHandlerMap.java:194)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:134)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:438)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:480)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:487)
    at com.google.tracing.TraceContext.runInContext(TraceContext.java:774)
    at com.google.tracing.TraceContext$DoInTraceContext.runInContext(TraceContext.java:751)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:342)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:334)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:484)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
    at java.lang.Thread.run(Thread.java:722)

和一个“关键”:

Uncaught exception from servlet
javax.servlet.UnavailableException: Initialization failed.
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.createHandler(AppVersionHandlerMap.java:228)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.getHandler(AppVersionHandlerMap.java:194)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:134)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:438)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:480)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:487)
    at com.google.tracing.TraceContext.runInContext(TraceContext.java:774)
    at com.google.tracing.TraceContext$DoInTraceContext.runInContext(TraceContext.java:751)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:342)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:334)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:484)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
    at java.lang.Thread.run(Thread.java:722)

web.xml 如下:

    <static-files>
        <include path="/stylesheets/main.css" />
    </static-files>

    <servlet>
        <servlet-name>home-jsp</servlet-name>
        <jsp-file>/WEB-INF/home.jsp</jsp-file>
    </servlet>
    <servlet-mapping>
        <servlet-name>home-jsp</servlet-name>
        <url-pattern>/WEB-INF/home.jsp</url-pattern>
    </servlet-mapping>  

    <servlet>
        <servlet-name>Home</servlet-name>
        <servlet-class>com.test.HomeServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Home</servlet-name>
        <url-pattern>/index/</url-pattern>
    </servlet-mapping>

你知道可能是什么问题吗?

4

2 回答 2

3

该文件夹与不应公开访问的文件夹一起,因为它们可能包含敏感的配置文件和不应单独请求的包含/标记/模板文件/WEB-INF/META-INF一般的 servletcontainer 对这些文件夹有一个内置的访问限制,这就解释了为什么即使您在web.xml.

如果有问题的 JSP 文件无论如何都应该是可公开访问的,那么将它放在/WEB-INF文件夹中根本没有意义。只需将 JSP 文件物理地移到该文件夹​​之外,然后删除整个文件<servlet><servlet-mapping>条目。这样,您必须能够通过简单地访问 JSP/home.jsp而不是/WEB-INF/home.jsp.

另一种选择,特别是如果您需要一些预处理业务逻辑,例如从 DB 加载一些应该在 JSP 中呈现的数据,将创建一个 servlet,该 servlet 映射到 eg 的 URL 模式/home并转发到有问题的 JSP 文件在其doGet()方法中。另请参阅我们的 servlets wiki 页面中的第二个 Hello World 示例。

于 2013-04-27T17:44:36.457 回答
0

您的 URL 模式是错误的,例如应该 /home.html。你的 URL 模式中不应该有 web-inf

于 2013-04-27T16:41:34.127 回答