获取IllegalStateException:在将部署的Java应用程序访问到Google App Engine时,没有这样的servlet:jsp

时间:2017-10-29 16:19:02

标签: java eclipse jsp google-app-engine servlets

我有这样的问题(this one),有app引擎。

我刚开始尝试使用eclipse插件将我的Java应用程序部署到App引擎,在localhost(使用tomcat-server和App引擎标准localhost)测试至少100次之后,它在本地工作正常。

但是当我将其部署为app引擎标准时,我在尝试访问任何servlet时遇到了此错误:

  

java.lang.IllegalStateException:没有这样的servlet:jsp   在org.eclipse.jetty.servlet.ServletHandler.updateMappings(ServletHandler.java:1535)   在org.eclipse.jetty.servlet.ServletHandler.doStart(ServletHandler.java:157)   at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)   at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)   在org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)   at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)   在org.eclipse.jetty.security.SecurityHandler.doStart(SecurityHandler.java:361)   在org.eclipse.jetty.security.ConstraintSecurityHandler.doStart(ConstraintSecurityHandler.java:448)   at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)   at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)   在org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)   at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)   在org.eclipse.jetty.server.handler.ScopedHandler.doStart(ScopedHandler.java:120)   在org.eclipse.jetty.server.session.SessionHandler.doStart(SessionHandler.java:116)   at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)   at org.eclipse.jetty.util.component.ContainerLifeCycle.start(ContainerLifeCycle.java:131)   在org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(ContainerLifeCycle.java:105)   at org.eclipse.jetty.server.handler.AbstractHandler.doStart(AbstractHandler.java:61)   在org.eclipse.jetty.server.handler.ScopedHandler.doStart(ScopedHandler.java:120)   at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:809)   at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:345)   在org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1406)   at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1368)   在org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:778)   在org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:262)   在org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:522)   at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68)   在com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.createHandler(AppVersionHandlerMap.java:244)   在com.google.apphosting.runtime.jetty9.AppVersionHandlerMap.getHandler(AppVersionHandlerMap.java:182)   在com.google.apphosting.runtime.jetty9.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:97)   在com.google.apphosting.runtime.JavaRuntime $ RequestRunnable.dispatchServletRequest(JavaRuntime.java:680)   在com.google.apphosting.runtime.JavaRuntime $ RequestRunnable.dispatchRequest(JavaRuntime.java:642)   在com.google.apphosting.runtime.JavaRuntime $ RequestRunnable.run(JavaRuntime.java:612)   在com.google.apphosting.runtime.JavaRuntime $ NullSandboxRequestRunnable.run(JavaRuntime.java:806)   在com.google.apphosting.runtime.ThreadGroupPool $ PoolEntry.run(ThreadGroupPool.java:274)   在java.lang.Thread.run(Thread.java:745)

我可以访问其他文件,图片,* .html。

我不知道它是否重要,我注意到在app引擎中我的web.xml文件是通过添加 servlet servelt-mapping 来修改的(映射)对于我的所有* .jsp文件,我认为是云存储,但不是在localhost。

在日志详细信息中的某处"此请求导致为您的应用程序启动了一个新进程,从而导致您的应用程序代码首次加载。因此,此请求可能需要更长的时间并且使用的CPU数量超过您的应用程序的典型请求。",我不知道是否与我的试用帐户相关联。

我正在使用datanucleus(datanucleus-api-jdo-5.1.0-release)库,我的web.xml中也有一些过滤器,索引文件和错误页面jsp。

Eclipse项目方面:
 App引擎标准环境:JRE8
 Servlet API:2.5
 JAVA:1.8
 JPA:1.0

我真的需要帮助,谢谢。

appengine-web.xml文件:



<?xml version="1.0" encoding="UTF-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">

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

  <runtime>java8</runtime>
</appengine-web-app>
&#13;
&#13;
&#13;

web.xml文件:

&#13;
&#13;
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:jsp="http://java.sun.com/xml/ns/javaee/jsp" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
  <display-name>my_project</display-name>
  
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  <!-- SERVLETS  DEFs -->
  
  <servlet>
    <servlet-name>Welcome</servlet-name>
    <servlet-class>my_root_package.servlets.controllers.Welcome</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>Statistic</servlet-name>
    <servlet-class>my_root_package.servlets.controllers.Statistic</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>Genea_Tree</servlet-name>
    <servlet-class>my_root_package.servlets.controllers.Genea_Tree</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>Genea_TreeEdit</servlet-name>
    <servlet-class>my_root_package.servlets.controllers.Genea_TreeEdit</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>New_event</servlet-name>
    <servlet-class>my_root_package.servlets.controllers.New_event</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>Inscription</servlet-name>
    <servlet-class>my_root_package.servlets.controllers.Inscription</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>InscriptionStep1</servlet-name>
    <servlet-class>my_root_package.servlets.controllers.InscriptionStep1</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>InscriptionStep2</servlet-name>
    <servlet-class>my_root_package.servlets.controllers.InscriptionStep2</servlet-class>
  </servlet>
  <servlet>
   <servlet-name>InscriptionConfirm</servlet-name>
    <servlet-class>my_root_package.servlets.controllers.InscriptionConfirm</servlet-class>
  </servlet>
  <servlet>
   <servlet-name>About</servlet-name>
    <servlet-class>my_root_package.servlets.controllers.About</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>AdminDashboard</servlet-name>
    <servlet-class>my_root_package.servlets.controllers.AdminDashboard</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>AdminAuthentification</servlet-name>
    <servlet-class>my_root_package.servlets.secutity.controllers.AdminAuthentification</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>AdminPassReset</servlet-name>
    <servlet-class>my_root_package.servlets.secutity.controllers.AdminPassReset</servlet-class>
  </servlet>
  <servlet>
    <servlet-name>Search</servlet-name>
    <servlet-class>my_root_package.servlets.controllers.Search</servlet-class>
  </servlet>
  
<!-- SERVLETS  MAPPING -->

  <servlet-mapping>
    <servlet-name>Welcome</servlet-name>
    <url-pattern>/welcome</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Statistic</servlet-name>
    <url-pattern>/statistic</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Genea_Tree</servlet-name>
    <url-pattern>/genea_tree</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Genea_TreeEdit</servlet-name>
    <url-pattern>/genea_tree/DetailEdit</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Genea_TreeEdit</servlet-name>
    <url-pattern>/genea_tree/DetailEditMore</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>New_event</servlet-name>
    <url-pattern>/new_event</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Inscription</servlet-name>
    <url-pattern>/inscription</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>InscriptionStep1</servlet-name>
    <url-pattern>/inscription/step1</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>InscriptionStep2</servlet-name>
    <url-pattern>/inscription/step2</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>InscriptionConfirm</servlet-name>
    <url-pattern>/inscription/Confirmation</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>About</servlet-name>
    <url-pattern>/about</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>AdminAuthentification</servlet-name>
    <url-pattern>/admin/Authentification</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>AdminPassReset</servlet-name>
    <url-pattern>/admin/PassReset</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>AdminDashboard</servlet-name>
    <url-pattern>/admin/dashboard</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>AdminDashboard</servlet-name>
    <url-pattern>/admin</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>AdminDashboard</servlet-name>
    <url-pattern>/admin/dashboard/insertionCommit</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>AdminDashboard</servlet-name>
    <url-pattern>/admin/dashboard/updateCommit</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>AdminDashboard</servlet-name>
    <url-pattern>/admin/dashboard/deleteCommit</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>AdminDashboard</servlet-name>
    <url-pattern>/admin/InsertionCommitPost</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>AdminDashboard</servlet-name>
    <url-pattern>/admin/updateCommitPost</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>AdminDashboard</servlet-name>
    <url-pattern>/admin/deleteCommitPost</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Search</servlet-name>
    <url-pattern>/AdvancedSearch</url-pattern>
  </servlet-mapping>
  <servlet-mapping>
    <servlet-name>Search</servlet-name>
    <url-pattern>/search</url-pattern>
  </servlet-mapping>

	<!-- ERROR PAGES -->

	<error-page>
		<exception-type>java.lang.Exception</exception-type>
		<location>/WEB-INF/errorManagement.jsp</location>
	</error-page>
	<error-page>
		<error-code>404</error-code>
		<location>/WEB-INF/404ErrorManagement.jsp</location>
	</error-page>

	<jsp-config>
		<jsp-property-group>
			<url-pattern>*.jsp</url-pattern>
			<page-encoding>UTF-8</page-encoding>
			<include-prelude>/WEB-INF/taglibs.jsp</include-prelude>
		</jsp-property-group>
	</jsp-config>
	
	
	<filter>
		<filter-name>encodingfilter</filter-name>
		<filter-class>my_root_package.filters.EncodingFilter</filter-class>
		<init-param>
			<param-name>encoding</param-name>
			<param-value>UTF-8</param-value>
		</init-param>
	</filter>

<!-- 	FILTERS DEFs -->
	<filter>
		<filter-name>multipartFilter</filter-name>
		<filter-class>my_root_package.filters.MultipartFilter</filter-class>
		<init-param>
			<param-name>maxFileSize</param-name>
			<param-value>360000</param-value>
		</init-param>
	</filter>

	<!-- 	FILTERS MAPPING -->
	<filter-mapping>
		<filter-name>encodingfilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

	<filter-mapping>
		<filter-name>multipartFilter</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>
	
</web-app>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

抱歉,我没有看到您的更新。我在你的web.xml中注意到你有一个引用*.jsp URL模式的jsp部分,但你的servlet映射都没有<jsp-config> <jsp-property-group> <url-pattern>*.jsp</url-pattern> <page-encoding>UTF-8</page-encoding> <include-prelude>/WEB-INF/taglibs.jsp</include-prelude> </jsp-property-group> </jsp-config> 后缀。

taglibs.jsp

GAE预编译JSP作为部署过程的一部分,因此我不确定这种类型的处理是否有效。您是否可以尝试在JSP中内联<%@ include file="/WEB-INF/taglibs.jsp" %> 的引用?您应该可以执行以下操作:

<jsp-config>

更新:我遇到了来自Google工程师的a post,宣布您所拥有的{{1}}个选项应该有效。如果包含有效,那么最好open a bug on the issue tracker

答案 1 :(得分:1)

虽然上述问题在新的基于Java 8的GAE中仍有待解决,但有一个适当的解决方案,不涉及在所有目标jsp文件上手动应用include标记。 问题的真正原因是远程GAE无法将jsp servlet规范映射到适用于Java的Google云运行时上的实际servlet类。

简而言之,有两种解决方案选项(我推荐选项B):

选项A(快捷方式解决方案):

1..为您的servlet提供带注释的名称jsp

@WebServlet(
    name = "jsp",
    urlPatterns = {"/hello", "/"}
)
public class HelloAppEngine extends HttpServlet {

2 ..然后在您的web.xml中,您可以自由地应用jsp-config规则。

...
    <jsp-config>
        <jsp-property-group>
            <description>JSP configuration for the open app</description>
            <url-pattern>/WEB-INF/*</url-pattern>
            <include-prelude>/WEB-INF/header.jspf</include-prelude>
            <include-coda>/WEB-INF/footer.jspf</include-coda>
        </jsp-property-group>
    </jsp-config>
...

这种方法的问题是(尽管它适用于远程GAE)在本地运行时它会崩溃(由于本地jsp servlet类冲突),因此您可能无法在本地检查开发。要避免选项A jsp黑客攻击和冲突,请使用选项B中的以下步骤。

选项B(适当的解决方案):

1 ..假设您正在使用maven构建,请将以下依赖项添加到pom.xml

<dependency>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>apache-jsp</artifactId>
    <version>9.4.8.v20171121</version>
</dependency>

2 ..然后在web.xml中添加以下配置。

<servlet>
    <servlet-name>jsp</servlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
</servlet>

3 ..并且在web.xml内,您可以自由地应用jsp-config规则。

...
    <jsp-config>
        <jsp-property-group>
            <description>JSP configuration for the open app</description>
            <url-pattern>/WEB-INF/*</url-pattern>
            <include-prelude>/WEB-INF/header.jspf</include-prelude>
            <include-coda>/WEB-INF/footer.jspf</include-coda>
        </jsp-property-group>
    </jsp-config>
...

希望这能解决您的问题。快乐的编码:)