我有一个GAE / J程序(使用JSP),它在dev服务器上运行得很好但是当我将它部署到App Engine时,它会返回:
错误:服务器错误
服务器遇到错误,无法完成您的请求。 如果问题仍然存在,请报告您的问题并提及此问题 错误消息和导致它的查询。
我使用Ecplise来部署我的程序。 我的环境和设置:
赢7 x64
的Eclipse 版本:Juno Service Release 2 建造ID:20130225-0426
JRE系统库[jdk1.7.0_21]
App Engine 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>
你知道可能出现什么问题吗?
答案 0 :(得分:3)
/WEB-INF
文件夹与/META-INF
文件夹一起不应公开访问,因为它们可能包含敏感配置文件和包含/标记/模板文件,不应单独请求。普通的servletcontainer对这些文件夹有内置的访问限制,这解释了为什么即使你在web.xml
中明确重新映射它也无法以这种方式访问JSP页面。
如果有问题的JSP文件毕竟是公共可访问的,那么将它放在/WEB-INF
文件夹中就没有意义了。只需将JSP文件物理移动到该文件夹之外,即可删除整个<servlet>
和<servlet-mapping>
条目。这样,您必须只需/home.jsp
而不是/WEB-INF/home.jsp
来访问JSP。
另一种选择,特别是如果您需要一些预处理业务逻辑,例如从应该在JSP中呈现的DB中加载一些数据,将创建一个映射到例如URL模式的servlet。 /home
并在其doGet()
方法中转发到相关JSP文件。另请参阅our servlets wiki page中途某处的第二个Hello World示例。
答案 1 :(得分:0)
您的网址格式错误,例如/home.html。 您的网址格式不应该是web-inf