0

I am trying to load an application to my local tomcat instance. When I input the address into the URL bar after starting tomcat I'm getting 404-not found error even though the resources were there. I did a lot of trial and error and found something in the DD file. A portion of the deployment descriptor contains following code..

<servlet>
    <servlet-name>invoker</servlet-name>
    <servlet-class>
        org.apache.catalina.servlets.InvokerServlet
    </servlet-class>
    <init-param>
        <param-name>debug</param-name>
        <param-value>0</param-value>
    </init-param>
    <load-on-startup>0</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>invoker</servlet-name>
    <url-pattern>/servlet/*</url-pattern>
</servlet-mapping>

When I comment this part from the web.xml file I was able to successfully get to the resources from the browser. So I'm pretty sure that the problem is in this code but I can't understand what it is. Can someone please explain what this code is doing and why am I getting error with this.? Thanks in advance.

Edit: For the record, I was trying to access resources directly under root folder. .. http://localhost/myapp/index.jsp

RKodakandla
  • 3,318
  • 13
  • 59
  • 79

1 Answers1

0

That's the legacy Tomcat-specific InvokerServlet which was present in ancient versions of Apache Tomcat (and still mentioned in poor and outdated tutorials/books). It was in the dark ages used to be able to invoke servlets without the need to map them in web.xml. You just have to enter the fully qualified servlet classname in the URL after the /servlet path.

It was later confirmed that it was a security hole and vulrenable to attacks. It was disabled and deprecated on Tomcat 5.0 around 2002(!) and removed in Tomcat 7.0 around 2009.

You can safely remove it. It adds no utter value. Since Tomcat 7.0 / Servlet 3.0 you even don't need to map servlets in web.xml anymore. You can use the @WebServlet annotation instead.

package com.example;

@WebServlet(urlPatterns = { "/MyServlet" })
public class MyServlet extends HttpServlet {

    // ...

}

As to the concrete problem why it works after you removed it, you'll probably have used the wrong URLs. Maybe you've called your context root path also servlet?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thank you very much for reply. Yes.. you were correct. This is a very old application (developed somewhere around 2000) and now they want me to fix bugs in that :( :(. I have never used old versions of tomcat(<5) so never knew about this.......so if I remove that part from my web.xml file, should I be mapping all the servlets in my application in the DD? The application environment used Tomcat6 so I am left without the annotation option. Thanks again. – RKodakandla Mar 22 '11 at 21:03
  • about context root.. no it was working only when I call resources directly under context root(I mean outside WEB-INF).. like jsp files. If I call something with /servlet I was getting the error – RKodakandla Mar 22 '11 at 21:10
  • Remove it anyway. You need to map all missing servlets yourself. Scan for classes which `extends HttpServlet` and verify if they are mapped in `web.xml`. – BalusC Mar 22 '11 at 21:12
  • OK thanks. Will try that. But just for knowledge.. this application is still successfully running on Tomcat6 on production machine. So was something configured on the server for it to run properly? Why was I getting the error? – RKodakandla Mar 22 '11 at 21:17
  • Honestly, I am not sure. Probably some Tomcat builtin prevention to prevent that the `InvokerServlet` get (ab)used :) What Tomcat version exactly are you using? – BalusC Mar 22 '11 at 21:18