troubleshooting Question

problem with simple struts application for datasource.

Avatar of mkarthik415
mkarthik415 asked on
JavaJSPJava EE
3 Comments1 Solution1209 ViewsLast Modified:
I am getting the following error in my logs ..I have copied commons-dbcp-1.0 jar file in to lib of my tomcat 6 and is also present in my application.

15:55:49,453 DEBUG PropertyMessageResources:327 -   Saving message key '.verifyMessageResourcesConfigs.invalid
15:55:49,453 ERROR ActionServlet:1090 - Initializing application data source org.apache.struts.action.DATA_SOURCE
java.lang.ClassNotFoundException: org.apache.commons.dbcp.BasicDataSource
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1645)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1491)
      at org.apache.struts.util.RequestUtils.applicationClass(RequestUtils.java:207)
      at org.apache.struts.util.RequestUtils.applicationInstance(RequestUtils.java:231)
      at org.apache.struts.action.ActionServlet.initModuleDataSources(ActionServlet.java:1081)
      at org.apache.struts.action.ActionServlet.init(ActionServlet.java:472)
      at javax.servlet.GenericServlet.init(GenericServlet.java:212)
      at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1173)
      at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:993)
      at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:4350)
      at org.apache.catalina.core.StandardContext.start(StandardContext.java:4659)
      at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:791)
      at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:771)
      at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:546)
      at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:905)
      at org.apache.catalina.startup.HostConfig.deployWARs(HostConfig.java:740)
      at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:500)
      at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1277)
      at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:321)
      at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:119)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1053)
      at org.apache.catalina.core.StandardHost.start(StandardHost.java:785)
      at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)
      at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:445)
      at org.apache.catalina.core.StandardService.start(StandardService.java:519)
      at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
      at org.apache.catalina.startup.Catalina.start(Catalina.java:581)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)
      at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)
15:56:39,859  INFO PropertyMessageResources:127 - Initializing, config='org.apache.struts.taglib.html.LocalStrings', returnNull=true



My struts-config.xml is



<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>

      <!-- Data Sources -->
      <data-sources>
            <data-source type="org.apache.commons.dbcp.BasicDataSource" key="org.apache.struts.action.DATA_SOURCE">
                <set-property property="driverClassName" value="org.gjt.mm.mysql.Driver" />
                <set-property property="url" value="jdbc:mysql://localhost:3306/login" />
                <set-property property="username" value="root" />
                <set-property property="password" value="12narkar" />
                <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 COUNT(*) FROM user" />
            </data-source>
      </data-sources>

      <!-- Form Beans -->
      <form-beans>
            <form-bean name="loginForm" type="strutsapp.forms.LoginForm">
            </form-bean>
      </form-beans>

      <!-- Global Exceptions -->
      <global-exceptions>
      </global-exceptions>

      <!-- Global Forwards -->
      <global-forwards>
      </global-forwards>

      <!-- Action Mappings -->
      <action-mappings>
            <action name="loginForm" path="/userRegistration" type="strutsapp.actions.LoginAction" input="logIn.jsp">
                  <forward contextRelative="true" name="success" path="/success.jsp">
                  </forward>
                  <forward name="fail" path="/fail.jsp">
                  </forward>
            </action>
      </action-mappings>

      <!-- Message Resources -->
      <message-resources parameter="strutsapp.resources.ApplicationResources"/>

</struts-config>



And my action class is

package strutsapp.actions;



import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import strutsapp.forms.LoginForm;

/**
 * @version       1.0
 * @author
 */
public class LoginAction extends Action

{
      Connection conn = null;
      private static Log log = LogFactory.getLog(LoginAction.class);
    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {
          javax.sql.DataSource dataSource;
           java.sql.Connection myConnection;
          log.trace("In execute method of UserRegistrationAction");
        ActionErrors errors = new ActionErrors();
        ActionForward forward = new ActionForward(); // return value
        LoginForm loginForm = (LoginForm) form;
        //DataSource dataSource = getDataSource(request, "userDB");

        try {
              
                  System.out.println("connected from database");
                  dataSource = getDataSource(request);
                  myConnection = dataSource.getConnection();
                  System.out.println("Disconnected from database");
                  log.trace("Inside try of execute method of UserRegistrationAction");

        } catch (Exception e) {

            // Report the error using the appropriate name and ID.
            errors.add("name", new ActionError("id"));

        }
        // If a message is required, save the specified key(s)
        // into the request for use by the <struts:errors> tag.

        if (!errors.isEmpty()) {
            saveErrors(request, errors);
        }
        // Write logic determining how the user should be forwarded.
        forward = mapping.findForward("success");
       // forward = mapping.findForward("fail");

        // Finish with
        return (forward);

    }
}

Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 3 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros