java.lang.NoSuchMethodError: javax.servlet.ServletContext.getEffectiveSessionTrackingModes()Ljava/util/Set;
我想要一个 servlet 来处理来自独立 java 程序的输入。如何在jboss中部署这个servlet。我将 servlet.class 文件放在 WEB-INF/classes 中,并在 web.xml 中将 servlet url 映射为“.do”。从我的 Java 客户端程序中,我使用 URL 对象打开了与 servlet 的连接。使用 localhost:8080/.do。但我收到以下错误:
ERROR [org.apache.catalina.connector.CoyoteAdapter] An exception or error occurred in the container during the request processing: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getEffectiveSessionTrackingModes()Ljava/util/Set; at org.apache.catalina.connector.CoyoteAdapter.postParseRequest(CoyoteAdapter.java:567) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:359) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951)
web.xml 文件内容:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "java.sun.com/j2ee/dtds/web-app_2_2.dtd">;
<web-app>
<servlet>
<servlet-name>ReverseServlet</servlet-name>
<servlet-class>ReverseServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ReverseServlet</servlet-name>
<url-pattern>/*.do</url-pattern>
</servlet-mapping>
</web-app>
i want to have a servlet to process inputs from a standalone java program. how to deploy this servlet in jboss. I put the servlet.class file in WEB-INF/classes and in web.xml i gave the servlet url mapping as ".do". From my Java client program i opened connected to the servlet using a URL object. using localhost:8080/.do. BUT i am getting the folowing error:
ERROR [org.apache.catalina.connector.CoyoteAdapter] An exception or error occurred in the container during the request processing: java.lang.NoSuchMethodError: javax.servlet.ServletContext.getEffectiveSessionTrackingModes()Ljava/util/Set; at org.apache.catalina.connector.CoyoteAdapter.postParseRequest(CoyoteAdapter.java:567) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:359) at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654) at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951)
web.xml file contents :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "java.sun.com/j2ee/dtds/web-app_2_2.dtd">;
<web-app>
<servlet>
<servlet-name>ReverseServlet</servlet-name>
<servlet-class>ReverseServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ReverseServlet</servlet-name>
<url-pattern>/*.do</url-pattern>
</servlet-mapping>
</web-app>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
引入了该方法在 Servlet 3.0 中。此错误至少可能有以下原因:
您的
web.xml
未声明至少符合 Servlet 3.0。您的 servlet 容器不至少支持 Servlet 3.0。
您在
/WEB-INF/lib
中有旧版本的 servlet 容器特定库。要解决此问题,
确保您的
web.xml
根声明符合 Servlet 3.0:确保您部署到 Servlet 3.0 兼容容器。对于 JBoss AS,至少版本为 6.0.0。
确保
/WEB-INF/lib
中没有这些库。他们不属于那里。这是初学者在“解决”IDE 中遇到的编译错误时常犯的错误。另请参阅 如何导入 javax我的 Eclipse 项目中是否有 .servlet API?您已声明您的
web.xml
符合 Servlet 2.2。这绝对是错误的。相应地修复它。This method is introduced in Servlet 3.0. This error can have at least the following causes:
Your
web.xml
is not declared conform at least Servlet 3.0.Your servlet container does not support at least Servlet 3.0.
You have servlet container specific libraries of an older version in
/WEB-INF/lib
.To solve this problem,
Ensure that your
web.xml
root declaration conforms Servlet 3.0:Ensure that you're deploying to a Servlet 3.0 compatible container. In case of JBoss AS that would be at least version 6.0.0.
Ensure that you don't have those libraries in
/WEB-INF/lib
. They do not belong there. This is a common beginner's mistake to "solve" compilation errors they faced in their IDE. See also How do I import the javax.servlet API in my Eclipse project?You've declared your
web.xml
conform Servlet 2.2. This is definitely wrong. Fix it accordingly.