write to eXist as a bean

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

write to eXist as a bean

chen_jing
Hi,all

I met trouble when I used the example(Put.java) to write to eXist as a javabean. It runs well when it run as an independent class, but when I call it through a JSP,it doesn't work.   Can you help me? Thanks a lot.



the JSP file is :

<%@ page language="java" %>
<!DOCTYPE HTML PUBLIC "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>
<title>Lomboz JSP</title>
</head>
<body bgcolor="#FFFFFF">
<jsp:useBean id="writer" scope="request" class="beans.WriteOver" />
<% writer.setCollection("/db/shakespeare/plays/test"); %>
<% writer.setFile("/afile.xml"); %>
write to exist

<% writer.storeToExist(); %>
</body>
</html>

and the javabean looks like:

package beans;
import org.xmldb.api.*;
import org.xmldb.api.base.*;
import org.xmldb.api.modules.*;
import java.io.*;

public class WriteOver {
 
    private String collection;
    private String file;
        private String URI = "xmldb:exist://localhost:8080/exist/xmlrpc";

    public void setCollection(String acollection) {
        collection = acollection;
        }
    public String getCollection() {
        return collection;
        }

    public void setFile(String afile) {
        file = afile;
        }
    public String getFile() {
        return file;
        }    
   
    public void storeToExist()throws Exception  {
       
        // initialize driver
                String driver = "org.exist.xmldb.DatabaseImpl";
                Class cl = Class.forName(driver);
                Database database = (Database)cl.newInstance();
                database.setProperty("create-database", "true");
                DatabaseManager.registerDatabase(database);
               
        // try to get collection
                Collection col =
                        DatabaseManager.getCollection(URI + collection, "admin", null);
                if(col == null) {
            // collection does not exist: get root collection and create.
            // for simplicity, we assume that the new collection is a
            // direct child of the root collection, e.g. /db/test.
            // the example will fail otherwise.
            Collection root = DatabaseManager.getCollection(URI + "/db");
            CollectionManagementService mgtService =
                (CollectionManagementService)root.getService("CollectionManagementService", "1.0");
            col = mgtService.createCollection(collection.substring("/db/".length()));
        }
                File f = new File(file);
        // create new XMLResource
                XMLResource document = (XMLResource)col.createResource(f.getName(), "XMLResource");
                document.setContent(f);
                System.out.print("storing document " + document.getId() + "...");
                col.storeResource(document);
                System.out.println("ok.");

    }


       }

 the error message is below:
type Exception report

message


 description The server encountered an internal error () that prevented it from fulfilling this request.
exception

javax.servlet.ServletException: org/xmldb/api/base/Resource
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


root cause

java.lang.NoClassDefFoundError: org/xmldb/api/base/Resource
        java.lang.Class.getDeclaredConstructors0(Native Method)
        java.lang.Class.privateGetDeclaredConstructors(Unknown Source)
        java.lang.Class.getConstructor0(Unknown Source)
        java.lang.Class.getConstructor(Unknown Source)
        org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1218)
        org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
        org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
        org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
        org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
        org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
        org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
        org.apache.jasper.compiler.Generator.generate(Generator.java:3270)
        org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:189)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
        org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
        org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
        org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
        org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
        org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
        javax.servlet.http.HttpServlet.service(HttpServlet.java:802)


note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.






-------------------------------------------------------
This SF.Net email is sponsored by:
Power Architecture Resource Center: Free content, downloads, discussions,
and more. http://solutions.newsforge.com/ibmarch.tmpl
_______________________________________________
Exist-open mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/exist-open