You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Luca Sabbio <lu...@fastwebnet.it> on 2007/04/27 17:38:55 UTC

Class is not a servlet

Hi, I'm working with Java 1.5.0.06, Tomcat 5.5.16 with Xindice 1.1b4 and Cocoon 2.1.10 deployed (and working).

I try to run a simple web application based on a servlet that update the Xindice XML DB
By the command line the PartsXupdate.java is compiled and the PartsXupdate.class works.

import org.xmldb.api.base.*;
import org.xmldb.api.modules.*;
import org.xmldb.api.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;


public class PartsXupdate {
   public static void main(String[] args) throws Exception {
      Collection col = null;
      try {
         String driver = "org.apache.xindice.client.xmldb.DatabaseImpl";
         Class c = Class.forName(driver);
         
         Database database = (Database) c.newInstance();
         DatabaseManager.registerDatabase(database);
         
         col = DatabaseManager.getCollection("xmldb:xindice://localhost:8080/db/test");
         
String xupd = "<xupdate:modifications version=\"1.0\" xmlns:xupdate=\"http://www.xmldb.org/xupdate\">"  + 
"<xupdate:insert-after select=\"/scheda/info\">"  +
"<xupdate:element name=\"commento\">Bel libro!</xupdate:element>"  + 
"</xupdate:insert-after>"  + 
"</xupdate:modifications>"; 



    String nome = "4.xml";   

            /* We are using XUpdateQueryService */
            XUpdateQueryService service =
               (XUpdateQueryService) col.getService("XUpdateQueryService", "1.0");
               
            service.updateResource(nome, xupd);
      }
      catch (XMLDBException e) {
         System.err.println("XML:DB Exception occurred " + e.errorCode);
      }
      finally {
          if (col != null) { col.close();}
      }
   }
}

But when I deploy the application on Tomcat 
and I do my post action http://localhost:8080/PartsXupdate/PartsXupdate from the form of provajava.html 
I get this error:
javax.servlet.ServletException: Class PartsXupdate is not a Servlet

I think that my web.xml is ok

<?xml version="1.0" encoding="ISO-8859-1"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">

  <display-name>esempio_servlet_xupdate</display-name>
  <description>
     Esempio di uso di servlet_xupdate
  </description>

<!-- JSPC servlet mappings start -->

<servlet>
        <servlet-name>PartsXupdate</servlet-name>
        <servlet-class>PartsXupdate</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>PartsXupdate</servlet-name>
        <url-pattern>/PartsXupdate</url-pattern>
    </servlet-mapping>

<welcome-file-list>
  <welcome-file>provajava.html</welcome-file>
</welcome-file-list>

</web-app>

Also classpath would be ok. Is there something to set in Tomcat?
I've read many mailing list and tried some changes but without results,
any suggestion would be appreciate.
Thanks

Re: Class is not a servlet

Posted by Luca Sabbio <lu...@fastwebnet.it>.
Ok, thank you all very much.
I'm still too newbie to make my servlet work (some problems with xindice)
but I've changed my java code and now it's really a servlet!

Grazie ancora, bye



----- Original Message ----- 
From: "Pid" <p...@pidster.com>
To: "Tomcat Users List" <us...@tomcat.apache.org>
Sent: Saturday, April 28, 2007 11:33 AM
Subject: Re: Class is not a servlet


> Seriously, David's recommendation is the way forwards.
> When he said, 'read the spec', he was indicating that you should at least 
> have a basic familiarity with what a Servlet is.
>
> There are *extensive* and complete tutorials from basic to advanced to 
> found for free online.  Search Google (other search engines are 
> available).
>
> Clue: Servlets are not written like a bean Class, you do not use the 
> main(...) method.
>
>
> rgds
>
> Pid
>
>
> Luca Sabbio wrote:
>> Thank you very much for the two answers.
>>
>> I don't know Java servlet enough to make PartsXupdate work
>> but now I have a way to follow.
>>
>>> I highly recommend reading the servlet spec.  There you will see a
>>> servlet extends HttpServlet and overrides one or more of it's methods.
>>>
>>> http://jcp.org/en/jsr/detail?id=154
>>>
>>> --David
>>
>>
>> Now that I've changed the class file,
>> and re-do the deployment, Tomcat first show me
>> HTTP Status 405 - HTTP method POST is not supported by this URL
>> than I modify PartsXupdate.java as below
>> and only work the out.println
>>
>> import org.xmldb.api.base.*;
>> import org.xmldb.api.modules.*;
>> import org.xmldb.api.*;
>> import javax.servlet.*;
>> import javax.servlet.http.*;
>> import java.io.*;
>>
>> public class PartsXupdate extends HttpServlet {
>>
>> public void doPost(HttpServletRequest request, HttpServletResponse 
>> response)
>> throws ServletException, IOException {
>>
>> PrintWriter out = response.getWriter();
>> out.println("Commento Inserito");
>> }
>>
>>
>>   public static void main(String[] args) throws Exception {
>>      Collection col = null;
>>      try {
>>         String driver = "org.apache.xindice.client.xmldb.DatabaseImpl";
>>         Class c = Class.forName(driver);
>>
>>         Database database = (Database) c.newInstance();
>>         DatabaseManager.registerDatabase(database);
>>
>>         col = 
>> DatabaseManager.getCollection("xmldb:xindice://localhost:8080/db/test");
>>
>> String xupd = "<xupdate:modifications version=\"1.0\" 
>> xmlns:xupdate=\"http://www.xmldb.org/xupdate\">"  +
>> "<xupdate:insert-after select=\"/scheda/info\">"  +
>> "<xupdate:element name=\"commento\">Bel libro!</xupdate:element>"  +
>> "</xupdate:insert-after>"  +
>> "</xupdate:modifications>";
>>
>>
>>
>>    String nome = "4.xml";
>>
>>            /* We are using XUpdateQueryService */
>>            XUpdateQueryService service =
>>               (XUpdateQueryService) col.getService("XUpdateQueryService", 
>> "1.0");
>>
>>            service.updateResource(nome, xupd);
>>      }
>>      catch (XMLDBException e) {
>>         System.err.println("XML:DB Exception occurred " + e.errorCode);
>>      }
>>      finally {
>>          if (col != null) { col.close();}
>>      }
>>   }
>> }
>>
>>
>>
>>> From: Luca Sabbio [mailto:lucasabbio@fastwebnet.it]
>>> public class PartsXupdate
>>
>> extends HttpServlet
>>
>>> {
>>
>> ...
>>
>> - Peter
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>> ---------------------------------------------------------------------
>> To start a new topic, e-mail: users@tomcat.apache.org
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>
> 


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Class is not a servlet

Posted by Pid <p...@pidster.com>.
Seriously, David's recommendation is the way forwards.
When he said, 'read the spec', he was indicating that you should at 
least have a basic familiarity with what a Servlet is.

There are *extensive* and complete tutorials from basic to advanced to 
found for free online.  Search Google (other search engines are available).

Clue: Servlets are not written like a bean Class, you do not use the 
main(...) method.


rgds

Pid


Luca Sabbio wrote:
> Thank you very much for the two answers.
> 
> I don't know Java servlet enough to make PartsXupdate work
> but now I have a way to follow.
> 
>> I highly recommend reading the servlet spec.  There you will see a
>> servlet extends HttpServlet and overrides one or more of it's methods.
>>
>> http://jcp.org/en/jsr/detail?id=154
>>
>> --David
> 
> 
> Now that I've changed the class file,
> and re-do the deployment, Tomcat first show me
> HTTP Status 405 - HTTP method POST is not supported by this URL
> than I modify PartsXupdate.java as below
> and only work the out.println
> 
> import org.xmldb.api.base.*;
> import org.xmldb.api.modules.*;
> import org.xmldb.api.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.io.*;
> 
> public class PartsXupdate extends HttpServlet {
> 
> public void doPost(HttpServletRequest request, HttpServletResponse 
> response)
> throws ServletException, IOException {
> 
> PrintWriter out = response.getWriter();
> out.println("Commento Inserito");
> }
> 
> 
>   public static void main(String[] args) throws Exception {
>      Collection col = null;
>      try {
>         String driver = "org.apache.xindice.client.xmldb.DatabaseImpl";
>         Class c = Class.forName(driver);
> 
>         Database database = (Database) c.newInstance();
>         DatabaseManager.registerDatabase(database);
> 
>         col = 
> DatabaseManager.getCollection("xmldb:xindice://localhost:8080/db/test");
> 
> String xupd = "<xupdate:modifications version=\"1.0\" 
> xmlns:xupdate=\"http://www.xmldb.org/xupdate\">"  +
> "<xupdate:insert-after select=\"/scheda/info\">"  +
> "<xupdate:element name=\"commento\">Bel libro!</xupdate:element>"  +
> "</xupdate:insert-after>"  +
> "</xupdate:modifications>";
> 
> 
> 
>    String nome = "4.xml";
> 
>            /* We are using XUpdateQueryService */
>            XUpdateQueryService service =
>               (XUpdateQueryService) 
> col.getService("XUpdateQueryService", "1.0");
> 
>            service.updateResource(nome, xupd);
>      }
>      catch (XMLDBException e) {
>         System.err.println("XML:DB Exception occurred " + e.errorCode);
>      }
>      finally {
>          if (col != null) { col.close();}
>      }
>   }
> }
> 
> 
> 
>> From: Luca Sabbio [mailto:lucasabbio@fastwebnet.it]
>> public class PartsXupdate
> 
> extends HttpServlet
> 
>> {
> 
> ...
> 
> - Peter
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 
> 


Re: Class is not a servlet

Posted by Luca Sabbio <lu...@fastwebnet.it>.
Thank you very much for the two answers.

I don't know Java servlet enough to make PartsXupdate work
but now I have a way to follow.

>I highly recommend reading the servlet spec.  There you will see a
> servlet extends HttpServlet and overrides one or more of it's methods.
>
> http://jcp.org/en/jsr/detail?id=154
>
> --David


Now that I've changed the class file,
and re-do the deployment, Tomcat first show me
HTTP Status 405 - HTTP method POST is not supported by this URL
than I modify PartsXupdate.java as below
and only work the out.println

import org.xmldb.api.base.*;
import org.xmldb.api.modules.*;
import org.xmldb.api.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class PartsXupdate extends HttpServlet {

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

PrintWriter out = response.getWriter();
out.println("Commento Inserito");
}


   public static void main(String[] args) throws Exception {
      Collection col = null;
      try {
         String driver = "org.apache.xindice.client.xmldb.DatabaseImpl";
         Class c = Class.forName(driver);

         Database database = (Database) c.newInstance();
         DatabaseManager.registerDatabase(database);

         col = 
DatabaseManager.getCollection("xmldb:xindice://localhost:8080/db/test");

String xupd = "<xupdate:modifications version=\"1.0\" 
xmlns:xupdate=\"http://www.xmldb.org/xupdate\">"  +
"<xupdate:insert-after select=\"/scheda/info\">"  +
"<xupdate:element name=\"commento\">Bel libro!</xupdate:element>"  +
"</xupdate:insert-after>"  +
"</xupdate:modifications>";



    String nome = "4.xml";

            /* We are using XUpdateQueryService */
            XUpdateQueryService service =
               (XUpdateQueryService) col.getService("XUpdateQueryService", 
"1.0");

            service.updateResource(nome, xupd);
      }
      catch (XMLDBException e) {
         System.err.println("XML:DB Exception occurred " + e.errorCode);
      }
      finally {
          if (col != null) { col.close();}
      }
   }
}



> From: Luca Sabbio [mailto:lucasabbio@fastwebnet.it]
> public class PartsXupdate

extends HttpServlet

> {

...

- Peter

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: Class is not a servlet

Posted by Peter Crowther <Pe...@melandra.com>.
> From: Luca Sabbio [mailto:lucasabbio@fastwebnet.it] 
> public class PartsXupdate

extends HttpServlet

> {

...

		- Peter

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Class is not a servlet

Posted by David Smith <dn...@cornell.edu>.
I highly recommend reading the servlet spec.  There you will see a 
servlet extends HttpServlet and overrides one or more of it's methods.

http://jcp.org/en/jsr/detail?id=154

--David

Luca Sabbio wrote:

>Hi, I'm working with Java 1.5.0.06, Tomcat 5.5.16 with Xindice 1.1b4 and Cocoon 2.1.10 deployed (and working).
>
>I try to run a simple web application based on a servlet that update the Xindice XML DB
>By the command line the PartsXupdate.java is compiled and the PartsXupdate.class works.
>
>import org.xmldb.api.base.*;
>import org.xmldb.api.modules.*;
>import org.xmldb.api.*;
>import javax.servlet.*;
>import javax.servlet.http.*;
>import java.io.*;
>
>
>public class PartsXupdate {
>   public static void main(String[] args) throws Exception {
>      Collection col = null;
>      try {
>         String driver = "org.apache.xindice.client.xmldb.DatabaseImpl";
>         Class c = Class.forName(driver);
>         
>         Database database = (Database) c.newInstance();
>         DatabaseManager.registerDatabase(database);
>         
>         col = DatabaseManager.getCollection("xmldb:xindice://localhost:8080/db/test");
>         
>String xupd = "<xupdate:modifications version=\"1.0\" xmlns:xupdate=\"http://www.xmldb.org/xupdate\">"  + 
>"<xupdate:insert-after select=\"/scheda/info\">"  +
>"<xupdate:element name=\"commento\">Bel libro!</xupdate:element>"  + 
>"</xupdate:insert-after>"  + 
>"</xupdate:modifications>"; 
>
>
>
>    String nome = "4.xml";   
>
>            /* We are using XUpdateQueryService */
>            XUpdateQueryService service =
>               (XUpdateQueryService) col.getService("XUpdateQueryService", "1.0");
>               
>            service.updateResource(nome, xupd);
>      }
>      catch (XMLDBException e) {
>         System.err.println("XML:DB Exception occurred " + e.errorCode);
>      }
>      finally {
>          if (col != null) { col.close();}
>      }
>   }
>}
>
>But when I deploy the application on Tomcat 
>and I do my post action http://localhost:8080/PartsXupdate/PartsXupdate from the form of provajava.html 
>I get this error:
>javax.servlet.ServletException: Class PartsXupdate is not a Servlet
>
>I think that my web.xml is ok
>
><?xml version="1.0" encoding="ISO-8859-1"?>
>
><web-app xmlns="http://java.sun.com/xml/ns/j2ee"
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
>    version="2.4">
>
>  <display-name>esempio_servlet_xupdate</display-name>
>  <description>
>     Esempio di uso di servlet_xupdate
>  </description>
>
><!-- JSPC servlet mappings start -->
>
><servlet>
>        <servlet-name>PartsXupdate</servlet-name>
>        <servlet-class>PartsXupdate</servlet-class>
>    </servlet>
>
>    <servlet-mapping>
>        <servlet-name>PartsXupdate</servlet-name>
>        <url-pattern>/PartsXupdate</url-pattern>
>    </servlet-mapping>
>
><welcome-file-list>
>  <welcome-file>provajava.html</welcome-file>
></welcome-file-list>
>
></web-app>
>
>Also classpath would be ok. Is there something to set in Tomcat?
>I've read many mailing list and tried some changes but without results,
>any suggestion would be appreciate.
>Thanks
>  
>


---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org