【发布时间】:2013-04-17 08:03:09
【问题描述】:
我有一个 Maven 项目,它在 Eclipse 中完全按照预期工作。它还在 Eclipse 之外构建和运行,但是当我尝试调用前端(JSP 网页)时,我得到以下信息:
访问 / 时出现问题。原因:
javax.servlet.ServletContext.getJspConfigDescriptor()Ljavax/servlet/descriptor/JspConfigDescriptor;原因:
java.lang.NoSuchMethodError: javax.servlet.ServletContext.getJspConfigDescriptor()Ljavax/servlet/descriptor/JspConfigDescriptor; ...
我环顾四周,似乎此消息与 Servlet 2.5 和 Servlet 3.0 之间的不兼容有关。但是我的 pom 中已经有 Servlet 3.0 作为依赖项:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
所以我不明白为什么在 eclipse 之外构建和部署时没有包含我需要的依赖项,即使构建本身是成功的。
知道是什么原因造成的以及如何解决吗?
编辑: 未在 web.xml 中配置 JSP 访问。 index.jsp 文件是使用这个 sn-p 为码头服务器设置的欢迎文件:
// configure webapp
WebAppContext webroot = new WebAppContext();
webroot.setResourceBase("src/main/webapp");
webroot.setContextPath("/");
webroot.setWelcomeFiles(new String[] {"index.jsp"});
webroot.setParentLoaderPriority(true);
server.setHandler(webroot);
剩下的几个jsp文件在webapp文件夹里。
编辑 2: 我检查了打包项目时创建的 jar 的内容,似乎 jar 中有多个 javax/servlet/Servlet.class 副本。这有点令人困惑。我假设我的 pom 中的这些其他依赖项(如下所列)必须添加额外的 Servlet.class 文件。
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-server</artifactId>
<version>8.1.8.v20121106</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-webapp</artifactId>
<version>8.1.8.v20121106</version>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jsp</artifactId>
<version>8.1.8.v20121106</version>
</dependency>
但我不确定如何解决这些问题...
如果有人有任何想法,我很想听听。我唯一真正的限制是我必须使用码头 8.1.8.v20121106。
【问题讨论】:
-
你是在 Tomcat 6 还是 Tomcat 7 中部署这个?
-
此应用程序已嵌入 Jetty
-
嵌入式码头的哪个版本?
-
你能显示你的
web.xml吗? -
不使用 web.xml 来访问 JSP。我已经用其他详细信息编辑了问题
标签: java jsp maven servlets web-applications