Problem invoking servlet - Weblogic

This is a discussion on Problem invoking servlet - Weblogic ; 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\Bible App;C:\bea\user_projects\infologic1\applications\B ibleApp\WEB-INF\classes. ...

+ Reply to Thread
Results 1 to 7 of 7

Thread: Problem invoking servlet

  1. Problem invoking servlet


    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\Bible App;C:\bea\user_projects\infologic1\applications\B ibleApp\WEB-INF\classes.
    java.lang.NoClassDefFoundError: /com/brainysoftware/burnaby/ControllerServlet
    (wrong name: ControllerServlet).
    at weblogic.servlet.internal.ServletStubImpl.prepareS ervlet
    ----------
    web.xml
    "http://java.sun.com/dtd/web-app_2_3.dtd">



    simple
    simplePage.jsp




    ControllerServlet
    com.brainysoftware.burnaby.ControllerServlet


    base
    http://localhost:7001/BibleApp/ControllerServlet


    jdbcDriver
    weblogic.jdbc.mssqlserver4.Driver


    imageUrl
    http://localhost:7001/BibleApp/images/


    dbUrl
    jdbc:weblogic:mssqlserver4:users@COMPAQSERVER


    dbUserName
    dinesh


    dbPassword
    werty69



    test
    menu_1.jsp



    HelloServlet
    HelloServlet



    ShowEmployees
    ShowEmployees



    HelloServlet
    /helloservlet



    test
    /test



    simple
    /simple


    ShowEmployees
    /ShowEmployees



    ControllerServlet
    /controlIt



    --------------
    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);

    }
    }



  2. Re: Problem invoking servlet


    Is the servlet class com/brainysoftware/burnaby/ControllerServlet in the WEB-INF\classes
    directory?




    "dinesh" wrote:
    >
    >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\Bible App;C:\bea\user_projects\infologic1\applications\B ibleApp\WEB-INF\classes.
    >java.lang.NoClassDefFoundError: /com/brainysoftware/burnaby/ControllerServlet
    >(wrong name: ControllerServlet).
    >at weblogic.servlet.internal.ServletStubImpl.prepareS ervlet
    >----------
    >web.xml
    > >2.3//EN"
    >"http://java.sun.com/dtd/web-app_2_3.dtd">
    >
    >
    >
    >simple
    >simplePage.jsp
    >
    >

    >
    >
    >ControllerServlet
    >com.brainysoftware.burnaby.ControllerServlet
    >
    >
    >
    >base
    >http://localhost:7001/BibleApp/ControllerServlet
    >

    >
    >jdbcDriver
    >weblogic.jdbc.mssqlserver4.Driver
    >

    >
    >imageUrl
    >http://localhost:7001/BibleApp/images/
    >

    >
    >dbUrl
    >jdbc:weblogic:mssqlserver4:users@COMPAQSERVER
    >

    >
    >dbUserName
    >dinesh
    >

    >
    >dbPassword
    >werty69
    >

    >

    >
    >test
    >menu_1.jsp
    >

    >
    >
    >HelloServlet
    >HelloServlet
    >

    >
    >
    >ShowEmployees
    >ShowEmployees
    >

    >
    >
    >HelloServlet
    >/helloservlet
    >

    >
    >
    >test
    >/test
    >

    >
    >
    >simple
    >/simple
    >

    >
    >ShowEmployees
    >/ShowEmployees
    >

    >
    >
    >ControllerServlet
    >/controlIt
    >

    >
    >

    >--------------
    >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);
    >
    >}
    >}
    >
    >



  3. Re: Problem invoking servlet


    yes it is along with a bean and 2 helper class files. I remember getting this error
    once before, but that was becase of improper syntax in web.xml.

    "Deepak Vohra" wrote:
    >
    >Is the servlet class com/brainysoftware/burnaby/ControllerServlet in
    >the WEB-INF\classes
    >directory?
    >
    >
    >
    >
    >"dinesh" wrote:
    >>
    >>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\Bible App;C:\bea\user_projects\infologic1\applications\B ibleApp\WEB-INF\classes.
    >>java.lang.NoClassDefFoundError: /com/brainysoftware/burnaby/ControllerServlet
    >>(wrong name: ControllerServlet).
    >>at weblogic.servlet.internal.ServletStubImpl.prepareS ervlet
    >>----------
    >>web.xml
    >> >>2.3//EN"
    >>"http://java.sun.com/dtd/web-app_2_3.dtd">
    >>
    >>
    >>
    >>simple
    >>simplePage.jsp
    >>
    >>

    >>
    >>
    >>ControllerServlet
    >>com.brainysoftware.burnaby.ControllerServlet
    >>
    >>
    >>
    >>base
    >>http://localhost:7001/BibleApp/ControllerServlet
    >>

    >>
    >>jdbcDriver
    >>weblogic.jdbc.mssqlserver4.Driver
    >>

    >>
    >>imageUrl
    >>http://localhost:7001/BibleApp/images/
    >>

    >>
    >>dbUrl
    >>jdbc:weblogic:mssqlserver4:users@COMPAQSERVER
    >>

    >>
    >>dbUserName
    >>dinesh
    >>

    >>
    >>dbPassword
    >>werty69
    >>

    >>

    >>
    >>test
    >>menu_1.jsp
    >>

    >>
    >>
    >>HelloServlet
    >>HelloServlet
    >>

    >>
    >>
    >>ShowEmployees
    >>ShowEmployees
    >>

    >>
    >>
    >>HelloServlet
    >>/helloservlet
    >>

    >>
    >>
    >>test
    >>/test
    >>

    >>
    >>
    >>simple
    >>/simple
    >>

    >>
    >>ShowEmployees
    >>/ShowEmployees
    >>

    >>
    >>
    >>ControllerServlet
    >>/controlIt
    >>

    >>
    >>

    >>--------------
    >>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);
    >>
    >>}
    >>}
    >>
    >>

    >



  4. Re: Problem invoking servlet


    I tried to add the servlet to the classpath with the following command:

    software\burnaby>java -cp -classpath c:\bea\user_projects\infologic1\application
    s\BibleApp\WEB-INF\classes\com\brainysoftware\burnaby\ControllerS ervlet.class


    Exception in thread "main" java.lang.NoClassDefFoundError: c:\bea\user_projects\
    infologic1\applications\BibleApp\WEB-INF\classes\com\brainysoftware\burnaby\Cont
    rollerServlet/class;

    Is there another way to do this?


    "Deepak Vohra" wrote:
    >
    >Is the servlet class com/brainysoftware/burnaby/ControllerServlet in
    >the WEB-INF\classes
    >directory?
    >
    >
    >
    >
    >"dinesh" wrote:
    >>
    >>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\Bible App;C:\bea\user_projects\infologic1\applications\B ibleApp\WEB-INF\classes.
    >>java.lang.NoClassDefFoundError: /com/brainysoftware/burnaby/ControllerServlet
    >>(wrong name: ControllerServlet).
    >>at weblogic.servlet.internal.ServletStubImpl.prepareS ervlet
    >>----------
    >>web.xml
    >> >>2.3//EN"
    >>"http://java.sun.com/dtd/web-app_2_3.dtd">
    >>
    >>
    >>
    >>simple
    >>simplePage.jsp
    >>
    >>

    >>
    >>
    >>ControllerServlet
    >>com.brainysoftware.burnaby.ControllerServlet
    >>
    >>
    >>
    >>base
    >>http://localhost:7001/BibleApp/ControllerServlet
    >>

    >>
    >>jdbcDriver
    >>weblogic.jdbc.mssqlserver4.Driver
    >>

    >>
    >>imageUrl
    >>http://localhost:7001/BibleApp/images/
    >>

    >>
    >>dbUrl
    >>jdbc:weblogic:mssqlserver4:users@COMPAQSERVER
    >>

    >>
    >>dbUserName
    >>dinesh
    >>

    >>
    >>dbPassword
    >>werty69
    >>

    >>

    >>
    >>test
    >>menu_1.jsp
    >>

    >>
    >>
    >>HelloServlet
    >>HelloServlet
    >>

    >>
    >>
    >>ShowEmployees
    >>ShowEmployees
    >>

    >>
    >>
    >>HelloServlet
    >>/helloservlet
    >>

    >>
    >>
    >>test
    >>/test
    >>

    >>
    >>
    >>simple
    >>/simple
    >>

    >>
    >>ShowEmployees
    >>/ShowEmployees
    >>

    >>
    >>
    >>ControllerServlet
    >>/controlIt
    >>

    >>
    >>

    >>--------------
    >>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);
    >>
    >>}
    >>}
    >>
    >>

    >



  5. Re: Problem invoking servlet



    Create a jar file from the classes referred by the servlet class & copy the jar
    file to the WEB-INF/lib directory.


    "dinesh" wrote:
    >
    >I tried to add the servlet to the classpath with the following command:
    >
    >
    >software\burnaby>java -cp -classpath c:\bea\user_projects\infologic1\application
    >s\BibleApp\WEB-INF\classes\com\brainysoftware\burnaby\ControllerS ervlet.class
    >
    >
    >Exception in thread "main" java.lang.NoClassDefFoundError: c:\bea\user_projects\
    >infologic1\applications\BibleApp\WEB-INF\classes\com\brainysoftware\burnaby\Cont
    >rollerServlet/class;
    >
    >Is there another way to do this?
    >
    >
    >"Deepak Vohra" wrote:
    >>
    >>Is the servlet class com/brainysoftware/burnaby/ControllerServlet in
    >>the WEB-INF\classes
    >>directory?
    >>
    >>
    >>
    >>
    >>"dinesh" wrote:
    >>>
    >>>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\Bible App;C:\bea\user_projects\infologic1\applications\B ibleApp\WEB-INF\classes.
    >>>java.lang.NoClassDefFoundError: /com/brainysoftware/burnaby/ControllerServlet
    >>>(wrong name: ControllerServlet).
    >>>at weblogic.servlet.internal.ServletStubImpl.prepareS ervlet
    >>>----------
    >>>web.xml
    >>> >>>2.3//EN"
    >>>"http://java.sun.com/dtd/web-app_2_3.dtd">
    >>>
    >>>
    >>>
    >>>simple
    >>>simplePage.jsp
    >>>
    >>>

    >>>
    >>>
    >>>ControllerServlet
    >>>com.brainysoftware.burnaby.ControllerServlet
    >>>
    >>>
    >>>
    >>>base
    >>>http://localhost:7001/BibleApp/ControllerServlet
    >>>

    >>>
    >>>jdbcDriver
    >>>weblogic.jdbc.mssqlserver4.Driver
    >>>

    >>>
    >>>imageUrl
    >>>http://localhost:7001/BibleApp/images/
    >>>

    >>>
    >>>dbUrl
    >>>jdbc:weblogic:mssqlserver4:users@COMPAQSERVER
    >>>

    >>>
    >>>dbUserName
    >>>dinesh
    >>>

    >>>
    >>>dbPassword
    >>>werty69
    >>>

    >>>

    >>>
    >>>test
    >>>menu_1.jsp
    >>>

    >>>
    >>>
    >>>HelloServlet
    >>>HelloServlet
    >>>

    >>>
    >>>
    >>>ShowEmployees
    >>>ShowEmployees
    >>>

    >>>
    >>>
    >>>HelloServlet
    >>>/helloservlet
    >>>

    >>>
    >>>
    >>>test
    >>>/test
    >>>

    >>>
    >>>
    >>>simple
    >>>/simple
    >>>

    >>>
    >>>ShowEmployees
    >>>/ShowEmployees
    >>>

    >>>
    >>>
    >>>ControllerServlet
    >>>/controlIt
    >>>

    >>>
    >>>

    >>>--------------
    >>>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);
    >>>
    >>>}
    >>>}
    >>>
    >>>

    >>

    >



  6. Re: Problem invoking servlet


    WEB-INF/classes dir & WEB-INF/lib dir are in the server classpath.



    "dinesh" wrote:
    >
    >Ok, I tried that and it's giving the same error. Do I need to define
    >the JAR file
    >in the web.xml?
    >Thanks.
    >
    >"Deepak Vohra" wrote:
    >>
    >>
    >>Create a jar file from the classes referred by the servlet class & copy
    >>the jar
    >>file to the WEB-INF/lib directory.
    >>
    >>
    >>"dinesh" wrote:
    >>>
    >>>I tried to add the servlet to the classpath with the following command:
    >>>
    >>>
    >>>software\burnaby>java -cp -classpath c:\bea\user_projects\infologic1\application
    >>>s\BibleApp\WEB-INF\classes\com\brainysoftware\burnaby\ControllerS ervlet.class
    >>>
    >>>
    >>>Exception in thread "main" java.lang.NoClassDefFoundError: c:\bea\user_projects\
    >>>infologic1\applications\BibleApp\WEB-INF\classes\com\brainysoftware\burnaby\Cont
    >>>rollerServlet/class;
    >>>
    >>>Is there another way to do this?
    >>>
    >>>
    >>>"Deepak Vohra" wrote:
    >>>>
    >>>>Is the servlet class com/brainysoftware/burnaby/ControllerServlet

    >in
    >>>>the WEB-INF\classes
    >>>>directory?
    >>>>
    >>>>
    >>>>
    >>>>
    >>>>"dinesh" wrote:
    >>>>>
    >>>>>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\Bible App;C:\bea\user_projects\infologic1\applications\B ibleApp\WEB-INF\classes.
    >>>>>java.lang.NoClassDefFoundError: /com/brainysoftware/burnaby/ControllerServlet
    >>>>>(wrong name: ControllerServlet).
    >>>>>at weblogic.servlet.internal.ServletStubImpl.prepareS ervlet
    >>>>>----------
    >>>>>web.xml
    >>>>> >>>>>2.3//EN"
    >>>>>"http://java.sun.com/dtd/web-app_2_3.dtd">
    >>>>>
    >>>>>
    >>>>>
    >>>>>simple
    >>>>>simplePage.jsp
    >>>>>
    >>>>>

    >>>>>
    >>>>>
    >>>>>ControllerServlet
    >>>>>com.brainysoftware.burnaby.ControllerServlet
    >>>>>
    >>>>>
    >>>>>
    >>>>>base
    >>>>>http://localhost:7001/BibleApp/ControllerServlet
    >>>>>

    >>>>>
    >>>>>jdbcDriver
    >>>>>weblogic.jdbc.mssqlserver4.Driver
    >>>>>

    >>>>>
    >>>>>imageUrl
    >>>>>http://localhost:7001/BibleApp/images/
    >>>>>

    >>>>>
    >>>>>dbUrl
    >>>>>jdbc:weblogic:mssqlserver4:users@COMPAQSERVER
    >>>>>

    >>>>>
    >>>>>dbUserName
    >>>>>dinesh
    >>>>>

    >>>>>
    >>>>>dbPassword
    >>>>>werty69
    >>>>>

    >>>>>

    >>>>>
    >>>>>test
    >>>>>menu_1.jsp
    >>>>>

    >>>>>
    >>>>>
    >>>>>HelloServlet
    >>>>>HelloServlet
    >>>>>

    >>>>>
    >>>>>
    >>>>>ShowEmployees
    >>>>>ShowEmployees
    >>>>>

    >>>>>
    >>>>>
    >>>>>HelloServlet
    >>>>>/helloservlet
    >>>>>

    >>>>>
    >>>>>
    >>>>>test
    >>>>>/test
    >>>>>

    >>>>>
    >>>>>
    >>>>>simple
    >>>>>/simple
    >>>>>

    >>>>>
    >>>>>ShowEmployees
    >>>>>/ShowEmployees
    >>>>>

    >>>>>
    >>>>>
    >>>>>ControllerServlet
    >>>>>/controlIt
    >>>>>

    >>>>>
    >>>>>

    >>>>>--------------
    >>>>>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);
    >>>>>
    >>>>>}
    >>>>>}
    >>>>>
    >>>>>
    >>>>
    >>>

    >>

    >



  7. Re: Problem invoking servlet

    >>>>> "dinesh" == dinesh writes:

    dinesh> Hello.
    dinesh> I'm trying to invoke a servlet. I get the following error:
    dinesh> javax.servlet.ServletException: [HTTP:101250][ServletContext(id=371807,name=BibleApp,context-path=/BibleApp)]:
    dinesh> Servlet class /com/brainysoftware/burnaby/ControllerServlet for servlet ControllerServlet
    dinesh> could not be loaded because a class on which it depends was not found in the classpath
    dinesh> C:\bea\user_projects\infologic1\applications\Bible App;C:\bea\user_projects\infologic1\applications\B ibleApp\WEB-INF\classes.
    dinesh> java.lang.NoClassDefFoundError: /com/brainysoftware/burnaby/ControllerServlet
    dinesh> (wrong name: ControllerServlet).
    dinesh> at weblogic.servlet.internal.ServletStubImpl.prepareS ervlet
    dinesh> --------------
    dinesh> ControllerServlet.class

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

    dinesh> public class ControllerServlet extends HttpServlet {

    Does the "ControllerServlet" class have a package statement? It needs to be in
    the "com.brainysoftware.burnaby" package.

    --
    ================================================== =================
    David M. Karr ; Java/J2EE/XML/Unix/C++
    dmkarr@earthlink.net ; SCJP; SCWCD



+ Reply to Thread