Trying to setup tomcat to use servlets

1k Views Asked by At

I'm following instructions found in Java All in one for Dummies 3rd edition

I downloaded tomcat and followed all the steps for setting it up, step 6 says. "Modify the web.xml file to enable the invoker servlet" It says to find the lines of code for the invoker and then comment them. I am currently in the web.xml file and searched for invoke, but nothing came up... should I code the invoker in myself? or umcomment a different line?(this book is 4 years old and may be outdated) Or just not change anything at all?

2

There are 2 best solutions below

1
On BEST ANSWER

I've just take a quick look up to the book and on page 407, there are the lines that you have to decomment or/else if not exist, add.

From the book;

<!--
     <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>2</load-on-startup>
     </servlet>
 -->

Anything located in between the "<!--" and "-->" will be interpreted as comments, which won't have any functional effect.

What you have to do is, to delete/remove the "<!--" and "-->" parts of this. Which is;

     <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>2</load-on-startup>
     </servlet>

As it is written on the book, on the same "web.xml" file, you also have to find the lines below;

<!--
    <servlet-mapping>
        <servlet-name>invoker</servlet-name>
        <url-pattern>/servlet/*</url-pattern>
    </servlet-mapping
 -->

And commenting out them to make them visible to the tomcat, as removing the same comment lines, like below;

<servlet-mapping>
    <servlet-name>invoker</servlet-name>
    <url-pattern>/servlet/*</url-pattern>
</servlet-mapping

Remember, you all have to execute these on the web.xml file.

And one more thing, If you cannot find these two parts, you can simply add these as below;

Just add them to the web.xml file as is;

     <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>2</load-on-startup>
     </servlet>


    <servlet-mapping>
        <servlet-name>invoker</servlet-name>
        <url-pattern>/servlet/*</url-pattern>
    </servlet-mapping
0
On

Just for your reference, this is my web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>IPNListener</display-name>
 <servlet>
        <servlet-name>PaypalListenerServlet</servlet-name> //your servlet name
        <servlet-class>com.paypal.ipn.PaypalListenerServlet</servlet-class>// your actual java class
    </servlet>
    <servlet-mapping>
        <servlet-name>PaypalListenerServlet</servlet-name>
        <url-pattern>/*</url-pattern>//pattern of your calling url
    </servlet-mapping>
</web-app>

Further you can give a look here for understanding of this web.xml file