acsess DB with struts:Error

Discussion in 'Java' started by marcelino, Feb 4, 2004.

  1. marcelino

    marcelino Guest

    Hi,

    still I'm a newbie handling struts. I tried to expand the
    struts-example with a mysql DB-Connection called test. I can access
    the example-welcome-site, but trying to activate the link to my site I
    become this error:

    ERROR: User database not loaded -- check servlet container logs for
    error messages.

    In the logs I find this two striking errors:

    1)
    2004-02-04 19:13:44 StandardContext[/test_struts]: Servlet
    /test_struts threw load() exception
    javax.servlet.ServletException: Servlet.init() for servlet action
    threw exception at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:963)
    etc.

    2)
    ----- Root Cause -----
    java.lang.NoClassDefFoundError:
    org/apache/struts/legacy/GenericDataSource at
    java.lang.ClassLoader.defineClass0(Native Method)
    etc.

    The versions I tried to find the DataSource (xml see below) out of
    TestAction.java:
    1)
    dataSource = servlet.findDataSource("org.apache.struts.action.DATA_SOURCE");

    DATA_SOURCE was the key easy-strus-editor generated- I changed it into
    personDS - see DataSources- tags below.
    After finding out method is deprecated tried with:
    2)
    dataSource = (DataSource)servlet.getServletContext().getAttribute("org.apache.struts.action.DATA_SOURCE");
    3)
    dataSource = (DataSource)servlet.getServletContext().getAttribute(Globals.DATA_SOURCE_KEY);
    4)
    dataSource = (DataSource)servlet.getServletContext().getAttribute("personDS");

    I tried it also with genericDS - still the same error!

    This are my DataSources:

    <!-- ========== Data Source Configuration
    =============================== -->
    <data-sources>
    <data-source type="org.apache.commons.dbcp.BasicDataSource"
    key="personDS">
    <set-property property="driverClassName"
    value="org.gjt.mm.mysql.Driver" />
    <set-property property="url"
    value="jdbc:mysql://localhost/protokollDB" />
    <set-property property="username" value="root" />
    <set-property property="password" />
    <set-property property="maxActive" value="10" />
    <set-property property="maxWait" value="5000" />
    <set-property property="defaultAutoCommit" value="false" />
    <set-property property="defaultReadOnly" value="false" />
    <set-property property="validationQuery" value="SELECT * FROM
    Person" />
    </data-source>
    <data-source type="org.apache.struts.util.GenericDataSource"
    key="genericDS">
    <set-property property="autoCommit" value="false" />
    <set-property property="description" value="Example Data Source
    Conf"/>
    <set-property property="driverClass"
    value="org.gjt.mm.mysql.Driver" />
    <set-property property="maxCount" value="4" />
    <set-property property="minCount" value="2" />
    <set-property property="password" />
    <set-property property="url"
    value="jdbc:mysql://localhost/protokollDB" />
    <set-property property="user" value="root" />
    </data-source>
    </data-sources>



    I built the following files:

    Interfaces:
    myTable.java
    myDB.java

    actionBean:
    TestAction.java

    formBean:
    TestForm.java

    jsp:
    testMyTable.jsp

    struts-conf:

    struts-conf-test.xml

    whats wrong?
    I would be very thankful for a hint.

    thanks in advance

    marcelino
     
    marcelino, Feb 4, 2004
    #1
    1. Advertising

  2. marcelino

    Sudsy Guest

    marcelino wrote:
    > Hi,
    >
    > still I'm a newbie handling struts. I tried to expand the
    > struts-example with a mysql DB-Connection called test. I can access
    > the example-welcome-site, but trying to activate the link to my site I
    > become this error:
    >
    > ERROR: User database not loaded -- check servlet container logs for
    > error messages.

    <snip>

    There is a method in the Action class called getDataSource. It requires
    an HttpServletRequest as an argument and will optionally accept a key.
    RTFM for details.
     
    Sudsy, Feb 5, 2004
    #2
    1. Advertising

  3. marcelino

    KD Guest

    Hi

    There is a file (struts-legacy.jar) that is missing from your tomcat lib.

    -Karim


    marcelino wrote:

    > Hi,
    >
    > still I'm a newbie handling struts. I tried to expand the
    > struts-example with a mysql DB-Connection called test. I can access
    > the example-welcome-site, but trying to activate the link to my site I
    > become this error:
    >
    > ERROR: User database not loaded -- check servlet container logs for
    > error messages.
    >
    > In the logs I find this two striking errors:
    >
    > 1)
    > 2004-02-04 19:13:44 StandardContext[/test_struts]: Servlet
    > /test_struts threw load() exception
    > javax.servlet.ServletException: Servlet.init() for servlet action
    > threw exception at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:963)
    > etc.
    >
    > 2)
    > ----- Root Cause -----
    > java.lang.NoClassDefFoundError:
    > org/apache/struts/legacy/GenericDataSource at
    > java.lang.ClassLoader.defineClass0(Native Method)
    > etc.
    >
    > The versions I tried to find the DataSource (xml see below) out of
    > TestAction.java:
    > 1)
    > dataSource = servlet.findDataSource("org.apache.struts.action.DATA_SOURCE");
    >
    > DATA_SOURCE was the key easy-strus-editor generated- I changed it into
    > personDS - see DataSources- tags below.
    > After finding out method is deprecated tried with:
    > 2)
    > dataSource = (DataSource)servlet.getServletContext().getAttribute("org.apache.struts.action.DATA_SOURCE");
    > 3)
    > dataSource = (DataSource)servlet.getServletContext().getAttribute(Globals.DATA_SOURCE_KEY);
    > 4)
    > dataSource = (DataSource)servlet.getServletContext().getAttribute("personDS");
    >
    > I tried it also with genericDS - still the same error!
    >
    > This are my DataSources:
    >
    > <!-- ========== Data Source Configuration
    > =============================== -->
    > <data-sources>
    > <data-source type="org.apache.commons.dbcp.BasicDataSource"
    > key="personDS">
    > <set-property property="driverClassName"
    > value="org.gjt.mm.mysql.Driver" />
    > <set-property property="url"
    > value="jdbc:mysql://localhost/protokollDB" />
    > <set-property property="username" value="root" />
    > <set-property property="password" />
    > <set-property property="maxActive" value="10" />
    > <set-property property="maxWait" value="5000" />
    > <set-property property="defaultAutoCommit" value="false" />
    > <set-property property="defaultReadOnly" value="false" />
    > <set-property property="validationQuery" value="SELECT * FROM
    > Person" />
    > </data-source>
    > <data-source type="org.apache.struts.util.GenericDataSource"
    > key="genericDS">
    > <set-property property="autoCommit" value="false" />
    > <set-property property="description" value="Example Data Source
    > Conf"/>
    > <set-property property="driverClass"
    > value="org.gjt.mm.mysql.Driver" />
    > <set-property property="maxCount" value="4" />
    > <set-property property="minCount" value="2" />
    > <set-property property="password" />
    > <set-property property="url"
    > value="jdbc:mysql://localhost/protokollDB" />
    > <set-property property="user" value="root" />
    > </data-source>
    > </data-sources>
    >
    >
    >
    > I built the following files:
    >
    > Interfaces:
    > myTable.java
    > myDB.java
    >
    > actionBean:
    > TestAction.java
    >
    > formBean:
    > TestForm.java
    >
    > jsp:
    > testMyTable.jsp
    >
    > struts-conf:
    >
    > struts-conf-test.xml
    >
    > whats wrong?
    > I would be very thankful for a hint.
    >
    > thanks in advance
    >
    > marcelino
     
    KD, Feb 6, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Katie Wright
    Replies:
    8
    Views:
    4,378
    Andrea Desole
    Jan 7, 2005
  2. Jason Us
    Replies:
    0
    Views:
    1,027
    Jason Us
    Oct 4, 2003
  3. jc1771
    Replies:
    0
    Views:
    438
    jc1771
    Dec 28, 2003
  4. sin
    Replies:
    3
    Views:
    754
    Sudsy
    Feb 22, 2004
  5. Pratap Das
    Replies:
    2
    Views:
    2,087
    Pratap Das
    Apr 5, 2004
Loading...

Share This Page