Problem invoking servlet

Discussion in 'Java' started by dinesh, Aug 3, 2003.

  1. dinesh

    dinesh Guest

    Hello.
    I'm trying to invoke a servlet. I get the following error:
    javax.servlet.ServletException:
    [HTTP:101250][ServletContext(id=371807,name=BibleApp,context-path=/BibleApp)
    ]: Servlet class /com/brainysoftware/burnaby/ControllerServlet for servlet
    ControllerServlet could not be loaded because a class on which it depends
    was not found in the classpath
    C:\bea\user_projects\infologic1\applications\BibleApp;C:\bea\user_projects\i
    nfologic1\applications\BibleApp\WEB-INF\classes.
    java.lang.NoClassDefFoundError:
    /com/brainysoftware/burnaby/ControllerServlet (wrong name:
    ControllerServlet).
    at weblogic.servlet.internal.ServletStubImpl.prepareServlet
    ----------
    web.xml
    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
    2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
    <web-app>
    <servlet>

    <servlet-name>simple</servlet-name>
    <jsp-file>simplePage.jsp</jsp-file>

    </servlet>

    <servlet>
    <servlet-name>ControllerServlet</servlet-name>
    <servlet-class>com.brainysoftware.burnaby.ControllerServlet</servlet-class>
    <!-- Define initial parameters that will be loaded into
    the ServletContext object in the controller servlet -->
    <init-param>
    <param-name>base</param-name>
    <param-value>http://localhost:7001/BibleApp/ControllerServlet</param-value>
    </init-param>
    <init-param>
    <param-name>jdbcDriver</param-name>
    <param-value>weblogic.jdbc.mssqlserver4.Driver</param-value>
    </init-param>
    <init-param>
    <param-name>imageUrl</param-name>
    <param-value>http://localhost:7001/BibleApp/images/</param-value>
    </init-param>
    <init-param>
    <param-name>dbUrl</param-name>
    <param-value>jdbc:weblogic:mssqlserver4:users@COMPAQSERVER</param-value>
    </init-param>
    <init-param>
    <param-name>dbUserName</param-name>
    <param-value>dinesh</param-value>
    </init-param>
    <init-param>
    <param-name>dbPassword</param-name>
    <param-value>werty69</param-value>
    </init-param>
    </servlet>
    <servlet>
    <servlet-name>test</servlet-name>
    <jsp-file>menu_1.jsp</jsp-file>
    </servlet>

    <servlet>
    <servlet-name>HelloServlet</servlet-name>
    <servlet-class>HelloServlet</servlet-class>
    </servlet>

    <servlet>
    <servlet-name>ShowEmployees</servlet-name>
    <servlet-class>ShowEmployees</servlet-class>
    </servlet>

    <servlet-mapping>
    <servlet-name>HelloServlet</servlet-name>
    <url-pattern>/helloservlet</url-pattern>
    </servlet-mapping>

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

    <servlet-mapping>
    <servlet-name>simple</servlet-name>
    <url-pattern>/simple</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
    <servlet-name>ShowEmployees</servlet-name>
    <url-pattern>/ShowEmployees</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
    <servlet-name>ControllerServlet</servlet-name>
    <url-pattern>/controlIt</url-pattern>
    </servlet-mapping>

    </web-app>
    --------------
    ControllerServlet.class

    import java.sql.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    import com.brainysoftware.burnaby.DbBean;

    public class ControllerServlet extends HttpServlet {

    /**Initialize global variables*/
    public void init(ServletConfig config) throws ServletException {

    System.out.println("initializing controller servlet.");

    ServletContext context = config.getServletContext();
    context.setAttribute("base", config.getInitParameter("base"));
    context.setAttribute("imageUrl", config.getInitParameter("imageUrl"));

    // instantiating the DbBean
    DbBean dbBean = new DbBean();
    // initialize the DbBean's fields
    dbBean.setDbUrl(config.getInitParameter("dbUrl"));
    dbBean.setDbUserName(config.getInitParameter("dbUserName"));
    dbBean.setDbPassword(config.getInitParameter("dbPassword"));

    // put the bean in the servlet context
    // the bean will be accessed from JSP pages
    context.setAttribute("dbBean", dbBean);

    try {
    // loading the database JDBC driver
    Class.forName(config.getInitParameter("jdbcDriver"));
    }
    catch (ClassNotFoundException e) {
    System.out.println(e.toString());
    }
    super.init(config);
    }


    /**Process the HTTP Get request*/
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    doPost(request, response);
    }

    /**Process the HTTP Post request*/
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

    String base = "/jsp/";
    String url = base + "Default.jsp";
    String action = request.getParameter("action");

    if (action!=null) {
    if (action.equals("search"))
    url = base + "SearchResults.jsp";
    else if (action.equals("browseCatalog"))
    url = base + "BrowseCatalog.jsp";
    else if (action.equals("productDetails"))
    url = base + "ProductDetails.jsp";
    else if (action.equals("productDetails"))
    url = base + "ProductDetails.jsp";
    else if (action.equals("addShoppingItem") ||
    action.equals("updateShoppingItem") ||
    action.equals("deleteShoppingItem") ||
    action.equals("displayShoppingCart"))
    url = base + "ShoppingCart.jsp";
    else if (action.equals("checkOut"))
    url = base + "CheckOut.jsp";
    else if (action.equals("order"))
    url = base + "Order.jsp";
    }
    RequestDispatcher requestDispatcher =
    getServletContext().getRequestDispatcher(url);
    requestDispatcher.forward(request, response);

    }
    }
    dinesh, Aug 3, 2003
    #1
    1. Advertising

  2. dinesh wrote:
    > I'm trying to invoke a servlet. I get the following error:
    > javax.servlet.ServletException:
    > [HTTP:101250][ServletContext(id=371807,name=BibleApp,context-path=/BibleApp)
    > ]: Servlet class /com/brainysoftware/burnaby/ControllerServlet for servlet
    > ControllerServlet could not be loaded because a class on which it depends
    > was not found in the classpath
    > C:\bea\user_projects\infologic1\applications\BibleApp;C:\bea\user_projects\i
    > nfologic1\applications\BibleApp\WEB-INF\classes.
    > java.lang.NoClassDefFoundError:
    > /com/brainysoftware/burnaby/ControllerServlet (wrong name:
    > ControllerServlet).
    > at weblogic.servlet.internal.ServletStubImpl.prepareServlet
    > ----------
    > web.xml
    > <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application
    > 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
    > <web-app>
    > <servlet>
    >
    > <servlet-name>simple</servlet-name>
    > <jsp-file>simplePage.jsp</jsp-file>
    >
    > </servlet>
    >
    > <servlet>
    > <servlet-name>ControllerServlet</servlet-name>
    > <servlet-class>com.brainysoftware.burnaby.ControllerServlet</servlet-class>


    [...]

    > --------------
    > ControllerServlet.class
    >
    > import java.sql.*;
    > import javax.servlet.*;
    > import javax.servlet.http.*;
    > import java.io.*;
    > import java.util.*;
    > import com.brainysoftware.burnaby.DbBean;
    >
    > public class ControllerServlet extends HttpServlet {


    [...]

    The source for the ControllerServlet class needs an appropriate package
    statement.


    John Bollinger
    John C. Bollinger, Aug 4, 2003
    #2
    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. Andy Fish
    Replies:
    4
    Views:
    2,415
    Andy Fish
    Dec 17, 2003
  2. Sean Clarke
    Replies:
    1
    Views:
    1,892
    Sudsy
    Jan 7, 2004
  3. circuit_breaker
    Replies:
    2
    Views:
    1,994
    Jack Jia
    Apr 4, 2004
  4. chamikara
    Replies:
    1
    Views:
    49,860
  5. Kira Yamato
    Replies:
    1
    Views:
    329
    Nigel Wade
    Jul 27, 2007
Loading...

Share This Page