2

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>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Rakesh
  • 43
  • 1
  • 2
  • 10
  • and if possible your servlet code. It seems like method you have mentioned in server is not present or there is some typo error in web.xml – Shekhar Jan 23 '12 at 09:35
  • ReverseServlet ReverseServlet ReverseServlet /*.do – Rakesh Jan 23 '12 at 09:41
  • Servlet code LINK http://docs.oracle.com/javase/tutorial/networking/urls/examples/ReverseServlet.java – Rakesh Jan 23 '12 at 09:47
  • Hi, Please remove web.xml contents from 'comments' section. I have added those in your 'question' itself. While adding content, I noticed that there is semi-colon (;) after element. Remove that semi-colon and re deploy app. Maybe it will work – Shekhar Jan 23 '12 at 09:51
  • I dint get you. Can u please explain in detail. der is no semi colon after doctype. – Rakesh Jan 23 '12 at 09:58
  • Currently your element is looking as follows : ; There is an semi colon at the end of line. You need to remove it. – Shekhar Jan 23 '12 at 10:22

1 Answers1

12

java.lang.NoSuchMethodError: javax.servlet.ServletContext.getEffectiveSessionTrackingModes()Ljava/util/Set;

This method is introduced in Servlet 3.0. This error can have at least the following causes:

  1. Your web.xml is not declared conform at least Servlet 3.0.

  2. Your servlet container does not support at least Servlet 3.0.

  3. You have servlet container specific libraries of an older version in /WEB-INF/lib.

To solve this problem,

  1. Ensure that your web.xml root declaration conforms Servlet 3.0:

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app 
        xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
        version="3.0">
    
        <!-- Config here. -->
    
    </web-app>
    
  2. 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.

  3. 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.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • I feel like this is only half the answer. Obviously it's possible to run a Servlet 2.2 app without encountering this exception; it's not as though all sites were perma-broken until Servlet 3.0 was released. – ruakh Nov 20 '13 at 07:43
  • @ruakh: I'm nowhere telling that this isn't possible. If you're actually unable to run a Servlet 2.2 webapp on a Servlet 3.0 container yourself, then your webapp conflicts point 3 in the answer. – BalusC Nov 20 '13 at 09:40
  • The OP didn't specify that (s)he was trying to use Servlet 3.0. Your answer even says "You've declared your `web.xml` conform Servlet 2.2. This is definitely wrong", but I don't see any basis for that. The problem is apparently a version mismatch between two things; your answer is about changing the 2.2 stuff to 3.0, but the OP might actually need the 3.0 stuff changed to 2.2. – ruakh Nov 20 '13 at 16:22
  • @ruakh: the line ` ` in OP's `web.xml` does that. – BalusC Nov 20 '13 at 16:25
  • No, you misunderstand me. the "You've declared your `web.xml` conform Servlet 2.2" part is obviously correct; it's the "This is definitely wrong" part that I don't see any basis for. – ruakh Nov 20 '13 at 16:26
  • (The reason I bring this up is -- I got to this question by Google because of a problem in one of my services. As far as I can tell, it's set up identically to two other services that do work, and all of their `web.xml`-s say 2.x. So I'm trying to figure out what's wrong with this third service. From your answer, I gather that it's that some sort of 3.0+ has snuck in, but your answer is silent about that possibility or how to address it.) – ruakh Nov 20 '13 at 16:27