You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xindice-users@xml.apache.org by FTL Africa <ft...@mutare.icon.co.zw> on 2003/01/24 18:08:55 UTC

ACCESSING DATABASE THROUGH SERVLET CALLED FROM INTERNET EXPLORER

Hi!

I am having an error message:
 Error: Error org.apache.xindice.client.xmldb.DatabaseImpl
when the my program gets to:
 Class c = Class.forName(driver);

I am accessing the program from IE browser not command line
  as is the case with the example RetrieveDocument.java.
I wrote the following code following the example RetrieveDocument.java that
came with xindice:

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

public class XindiceServlet7 extends HttpServlet {

    // The method corresponding to HTTP GET
    public void doGet(HttpServletRequest request, HttpServletResponse
response)
        throws ServletException, IOException {
         Collection col = null;
         PrintWriter out = response.getWriter();
            try {
                String driver =
"org.apache.xindice.client.xmldb.DatabaseImpl";
                Class c = Class.forName(driver);    /* exception from here*/

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

DatabaseManager.getCollection("xmldb:xindice:///db/addressbook");

                 XMLResource document = (XMLResource)
col.getResource("address");
                 if (document != null) {
                        out.println("Document ");
                } else {
                        out.println("Document not found");
                }
            } catch(Exception e) {
                out.write("Error " + e.getMessage());
            }
            finally {
            }
      }
}


Thanks in advance

Alisemore Ndowora



Re: ACCESSING DATABASE THROUGH SERVLET CALLED FROM INTERNET EXPLORER

Posted by FTL Africa <ft...@mutare.icon.co.zw>.
Thank you for your help it's getting me well going. However I have 2 more
problems:

            1) An XUpdate problem
            2) Running the servlet from another location other than the
default examples location;

1)
Please find attached the source code to the servlet that I coded
(XindiceServlet.java). The servlet is running well up to the point that the
following function is called XUpdateQueryService's update() : See the
function UpdateDocument() - line:
        long count = service.update(xupdate);  /* error from here */
NB The string xupdate is as follows

        String xupdate = "<xu:modifications version=\"1.0\"" +
             "      xmlns:xu=\"http://www.xmldb.org/xupdate\">" +
             "   <xu:update select=\"/person/phone[@type = 'work']\">" +
             "       480-300-3003" +
             "   </xu:update>" +
             "</xu:modifications>";

I am getting the following error message:
      Query Processing error

The items I am trying to update are valid, when I intentionally use wrong
elements it really sees that there are no items to update.

2)
Also I am unable to run our servlets from any other directory except the
examples directory, can you help us configure so that we are able from any
other areas of the system.

I had wanted to create a new application called XindiceServlet. Below is
what I had done.

2.1. Making directory.

XindiceSample/
  -WEB-INF/
    - classes/   Put the class file of serve let.
    - lib/    Put library of Xindice


C:\> cd %CATALINA_HOME%
%CATALINA_HOME%> cd webapps«
%CATALINA_HOME%> mkdir XindiceSample«
%CATALINA_HOME%> cd XindiceSample«
%CATALINA_HOME%> mkdir WEB-INF«
%CATALINA_HOME%> cd WEB-INF«
%CATALINA_HOME%> mkdir classes«
%CATALINA_HOME%> mkdir lib«


2.2. Copy followings to WEB-INF/lib from java/lib

openorb-1.2.0.jar
xalan-2.0.1.jar
xerces-1.4.3.jar
xindice.jar
xmldb.jar


2.3. Setting of class path

C:\> set XINDICE_LIB=%XINDICE_HOME%\java\lib«
C:\> set CLASSPATH=.;%XINDICE_LIB%\xmldb.jar;%
XINDICE_LIB%\xindice.jar;%XINDICE_LIB%\openorb-1.2.0.jar;%XINDICE_LIB%\xerce
s-1.4.3.jar;%XINDICE_LIB%\xalan-2.0.1.jar;%CATALINA_HOME%\common\lib\servlet
.jar

Thanks in advance

Alisemore Dudzai Ndowora









Re: ACCESSING DATABASE THROUGH SERVLET CALLED FROM INTERNET EXPLORER

Posted by jmt <jm...@dxdydz.net>.
Your application does not care - at least at this stage - whether it is 
accessed via IE or any other browser.

When your servlet is accessed, either through the init method or through 
post/get methods, you want your database to be connected to ; consequently 
you provide the servlet a driver class, in the present case a driver that 
implements xmldb with Xindice.
If you want your servlet to be able to load this driver, it must first find 
it. Depending on the java dev kit you use, several locations are possible.
In tomcat, a standard location can be
webapps/your_application/WEB_INF/lib
But other places are possible, for instance for tomcat-4.1.12 :
$TOMCAT_HOME/shared/lib.
You can also start tomcat with a script that provides a class path containing 
this driver class.



On Monday 27 January 2003 08:28, FTL Africa wrote:
> Thank you very much for the help.
>
> Can you please help me on the following.
> How do I make my program find the "driver" class?
> Which files do I have to alter to have the driver seen from the IE?
> Please take note that when I am in the same directory, that contains both
> servlet class and non-servlet class, and run the non-servlet class from
> command line it runs, but when I try accessing the servlet version of the
> program it then fails.
>
> Regards
> Alisemore Dudzai Ndowora
>
> ----- Original Message -----
> From: jmt <jm...@dxdydz.net>
> To: <xi...@xml.apache.org>; FTL Africa <ft...@mutare.icon.co.zw>
> Sent: Friday, January 24, 2003 7:16 PM
> Subject: Re: ACCESSING DATABASE THROUGH SERVLET CALLED FROM INTERNET
> EXPLORER
>
> > This is caused by your program not finding the "driver" class. Your
> > web-application should contain a directory "lib" where it could find the
> > driver, or you could start your application container in a way its
>
> CLASSPATH
>
> > points to it.
> >
> > jmt
> >
> > On Friday 24 January 2003 18:08, FTL Africa wrote:
> > > Hi!
> > >
> > > I am having an error message:
> > >  Error: Error org.apache.xindice.client.xmldb.DatabaseImpl
> > > when the my program gets to:
> > >  Class c = Class.forName(driver);
> > >
> > > I am accessing the program from IE browser not command line
> > >   as is the case with the example RetrieveDocument.java.
> > > I wrote the following code following the example RetrieveDocument.java
>
> that
>
> > > came with xindice:
> > >
> > > import java.io.*;
> > > import javax.servlet.*;
> > > import javax.servlet.http.*;
> > > import org.xmldb.api.base.*;
> > > import org.xmldb.api.modules.*;
> > > import org.xmldb.api.*;
> > > import org.w3c.dom.*;
> > >
> > > public class XindiceServlet7 extends HttpServlet {
> > >
> > >     // The method corresponding to HTTP GET
> > >     public void doGet(HttpServletRequest request, HttpServletResponse
> > > response)
> > >         throws ServletException, IOException {
> > >          Collection col = null;
> > >          PrintWriter out = response.getWriter();
> > >             try {
> > >                 String driver =
> > > "org.apache.xindice.client.xmldb.DatabaseImpl";
> > >                 Class c = Class.forName(driver);    /* exception from
> > > here*/
> > >
> > >                  Database database = (Database) c.newInstance();
> > >                  DatabaseManager.registerDatabase(database);
> > >                  col =
> > >
> > > DatabaseManager.getCollection("xmldb:xindice:///db/addressbook");
> > >
> > >                  XMLResource document = (XMLResource)
> > > col.getResource("address");
> > >                  if (document != null) {
> > >                         out.println("Document ");
> > >                 } else {
> > >                         out.println("Document not found");
> > >                 }
> > >             } catch(Exception e) {
> > >                 out.write("Error " + e.getMessage());
> > >             }
> > >             finally {
> > >             }
> > >       }
> > > }
> > >
> > >
> > > Thanks in advance
> > >
> > > Alisemore Ndowora

Re: ACCESSING DATABASE THROUGH SERVLET CALLED FROM INTERNET EXPLORER

Posted by FTL Africa <ft...@mutare.icon.co.zw>.
Thank you very much for the help.

Can you please help me on the following.
How do I make my program find the "driver" class?
Which files do I have to alter to have the driver seen from the IE?
Please take note that when I am in the same directory, that contains both
servlet class and non-servlet class, and run the non-servlet class from
command line it runs, but when I try accessing the servlet version of the
program it then fails.

Regards
Alisemore Dudzai Ndowora

----- Original Message -----
From: jmt <jm...@dxdydz.net>
To: <xi...@xml.apache.org>; FTL Africa <ft...@mutare.icon.co.zw>
Sent: Friday, January 24, 2003 7:16 PM
Subject: Re: ACCESSING DATABASE THROUGH SERVLET CALLED FROM INTERNET
EXPLORER


> This is caused by your program not finding the "driver" class. Your
> web-application should contain a directory "lib" where it could find the
> driver, or you could start your application container in a way its
CLASSPATH
> points to it.
>
> jmt
>
>
> On Friday 24 January 2003 18:08, FTL Africa wrote:
> > Hi!
> >
> > I am having an error message:
> >  Error: Error org.apache.xindice.client.xmldb.DatabaseImpl
> > when the my program gets to:
> >  Class c = Class.forName(driver);
> >
> > I am accessing the program from IE browser not command line
> >   as is the case with the example RetrieveDocument.java.
> > I wrote the following code following the example RetrieveDocument.java
that
> > came with xindice:
> >
> > import java.io.*;
> > import javax.servlet.*;
> > import javax.servlet.http.*;
> > import org.xmldb.api.base.*;
> > import org.xmldb.api.modules.*;
> > import org.xmldb.api.*;
> > import org.w3c.dom.*;
> >
> > public class XindiceServlet7 extends HttpServlet {
> >
> >     // The method corresponding to HTTP GET
> >     public void doGet(HttpServletRequest request, HttpServletResponse
> > response)
> >         throws ServletException, IOException {
> >          Collection col = null;
> >          PrintWriter out = response.getWriter();
> >             try {
> >                 String driver =
> > "org.apache.xindice.client.xmldb.DatabaseImpl";
> >                 Class c = Class.forName(driver);    /* exception from
> > here*/
> >
> >                  Database database = (Database) c.newInstance();
> >                  DatabaseManager.registerDatabase(database);
> >                  col =
> >
> > DatabaseManager.getCollection("xmldb:xindice:///db/addressbook");
> >
> >                  XMLResource document = (XMLResource)
> > col.getResource("address");
> >                  if (document != null) {
> >                         out.println("Document ");
> >                 } else {
> >                         out.println("Document not found");
> >                 }
> >             } catch(Exception e) {
> >                 out.write("Error " + e.getMessage());
> >             }
> >             finally {
> >             }
> >       }
> > }
> >
> >
> > Thanks in advance
> >
> > Alisemore Ndowora
>



Re: ACCESSING DATABASE THROUGH SERVLET CALLED FROM INTERNET EXPLORER

Posted by jmt <jm...@dxdydz.net>.
This is caused by your program not finding the "driver" class. Your 
web-application should contain a directory "lib" where it could find the 
driver, or you could start your application container in a way its CLASSPATH 
points to it.

jmt


On Friday 24 January 2003 18:08, FTL Africa wrote:
> Hi!
>
> I am having an error message:
>  Error: Error org.apache.xindice.client.xmldb.DatabaseImpl
> when the my program gets to:
>  Class c = Class.forName(driver);
>
> I am accessing the program from IE browser not command line
>   as is the case with the example RetrieveDocument.java.
> I wrote the following code following the example RetrieveDocument.java that
> came with xindice:
>
> import java.io.*;
> import javax.servlet.*;
> import javax.servlet.http.*;
> import org.xmldb.api.base.*;
> import org.xmldb.api.modules.*;
> import org.xmldb.api.*;
> import org.w3c.dom.*;
>
> public class XindiceServlet7 extends HttpServlet {
>
>     // The method corresponding to HTTP GET
>     public void doGet(HttpServletRequest request, HttpServletResponse
> response)
>         throws ServletException, IOException {
>          Collection col = null;
>          PrintWriter out = response.getWriter();
>             try {
>                 String driver =
> "org.apache.xindice.client.xmldb.DatabaseImpl";
>                 Class c = Class.forName(driver);    /* exception from
> here*/
>
>                  Database database = (Database) c.newInstance();
>                  DatabaseManager.registerDatabase(database);
>                  col =
>
> DatabaseManager.getCollection("xmldb:xindice:///db/addressbook");
>
>                  XMLResource document = (XMLResource)
> col.getResource("address");
>                  if (document != null) {
>                         out.println("Document ");
>                 } else {
>                         out.println("Document not found");
>                 }
>             } catch(Exception e) {
>                 out.write("Error " + e.getMessage());
>             }
>             finally {
>             }
>       }
> }
>
>
> Thanks in advance
>
> Alisemore Ndowora