Servlet-to-JSP using Tomcat 4.1

Discussion in 'Java' started by Rex, Aug 24, 2003.

  1. Rex

    Rex Guest

    Im running Tomcat 4.1 with JDK 1.4.2 on Win XP SP1
    I have made a simple database search page (using MSAccess) that fetches
    records using jdbc odbc drivers.
    A servlet does the database processing, puts the finished search results
    into a vector (each result is represented by a javabean) and i use the
    following code in doPost():

    session.setAttribute("results",l_vecTmp); // l_vecTmp is the vector
    ServletConfig sc=getServletConfig();
    ServletContext sx=sc.getServletContext();
    RequestDispatcher rd=sx.getRequestDispatcher("/results.jsp");
    rd.forward(req, res); //the 2 params are the standard httpservlet request
    and response objects that were passed to the servlet

    In the JSP, I use the following code:
    <%! int i;
    Vector l_vecTmp;%>


    <%! SearchResultBean l_srb;
    int l_iSize=l_vecTmp.size(); %>
    <% try
    {
    l_vecTmp=(Vector)request.getAttribute("results");
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    %>

    The directory structure is as follows-
    Location of results.jsp:
    <tomcat-root>\webapps\studentsearch
    Location of servlet:
    <tomcat-root>\webapps\studentsearch\WEB-INF\classes

    When I run the application, I get a JasperException in the servlet, at the
    requestdispatcher line.
    Does it mean the servlet cant find the JSP?
    Do i have to add the JSP to the web.xml deployment descriptor?

    ANy help appreciated

    Rex
     
    Rex, Aug 24, 2003
    #1
    1. Advertising

  2. Rex

    Andy Flowers Guest

    What is the exception ?

    "Rex" <> wrote in message
    news:biafbu$78agv$-berlin.de...
    > Im running Tomcat 4.1 with JDK 1.4.2 on Win XP SP1
    > I have made a simple database search page (using MSAccess) that fetches
    > records using jdbc odbc drivers.
    > A servlet does the database processing, puts the finished search results
    > into a vector (each result is represented by a javabean) and i use the
    > following code in doPost():
    >
    > session.setAttribute("results",l_vecTmp); // l_vecTmp is the vector
    > ServletConfig sc=getServletConfig();
    > ServletContext sx=sc.getServletContext();
    > RequestDispatcher rd=sx.getRequestDispatcher("/results.jsp");
    > rd.forward(req, res); //the 2 params are the standard httpservlet

    request
    > and response objects that were passed to the servlet
    >
    > In the JSP, I use the following code:
    > <%! int i;
    > Vector l_vecTmp;%>
    >
    >
    > <%! SearchResultBean l_srb;
    > int l_iSize=l_vecTmp.size(); %>
    > <% try
    > {
    > l_vecTmp=(Vector)request.getAttribute("results");
    > }
    > catch(Exception e)
    > {
    > e.printStackTrace();
    > }
    > %>
    >
    > The directory structure is as follows-
    > Location of results.jsp:
    > <tomcat-root>\webapps\studentsearch
    > Location of servlet:
    > <tomcat-root>\webapps\studentsearch\WEB-INF\classes
    >
    > When I run the application, I get a JasperException in the servlet, at the
    > requestdispatcher line.
    > Does it mean the servlet cant find the JSP?
    > Do i have to add the JSP to the web.xml deployment descriptor?
    >
    > ANy help appreciated
    >
    > Rex
    >
    >
     
    Andy Flowers, Aug 24, 2003
    #2
    1. Advertising

  3. Rex

    Rex Guest

    It says JasperException ...
     
    Rex, Aug 24, 2003
    #3
  4. Rex

    Rex Guest

    Also..do u know where one should put files that the application loads? I
    have stored database settings in a text file. I put it in the /bin folder,
    the application folder, and its Webinf folder, but it says file not
    found..(i tried this after the jasper exception problem)
    "Andy Flowers" <> wrote in message
    news:eek:F32b.2342$...
    > What is the exception ?
    >
    > "Rex" <> wrote in message
    > news:biafbu$78agv$-berlin.de...
    > > Im running Tomcat 4.1 with JDK 1.4.2 on Win XP SP1
    > > I have made a simple database search page (using MSAccess) that fetches
    > > records using jdbc odbc drivers.
    > > A servlet does the database processing, puts the finished search results
    > > into a vector (each result is represented by a javabean) and i use the
    > > following code in doPost():
    > >
    > > session.setAttribute("results",l_vecTmp); // l_vecTmp is the vector
    > > ServletConfig sc=getServletConfig();
    > > ServletContext sx=sc.getServletContext();
    > > RequestDispatcher rd=sx.getRequestDispatcher("/results.jsp");
    > > rd.forward(req, res); //the 2 params are the standard httpservlet

    > request
    > > and response objects that were passed to the servlet
    > >
    > > In the JSP, I use the following code:
    > > <%! int i;
    > > Vector l_vecTmp;%>
    > >
    > >
    > > <%! SearchResultBean l_srb;
    > > int l_iSize=l_vecTmp.size(); %>
    > > <% try
    > > {
    > > l_vecTmp=(Vector)request.getAttribute("results");
    > > }
    > > catch(Exception e)
    > > {
    > > e.printStackTrace();
    > > }
    > > %>
    > >
    > > The directory structure is as follows-
    > > Location of results.jsp:
    > > <tomcat-root>\webapps\studentsearch
    > > Location of servlet:
    > > <tomcat-root>\webapps\studentsearch\WEB-INF\classes
    > >
    > > When I run the application, I get a JasperException in the servlet, at

    the
    > > requestdispatcher line.
    > > Does it mean the servlet cant find the JSP?
    > > Do i have to add the JSP to the web.xml deployment descriptor?
    > >
    > > ANy help appreciated
    > >
    > > Rex
    > >
    > >

    >
    >
     
    Rex, Aug 24, 2003
    #4
  5. Rex

    Andy Flowers Guest

    Take a look at the server logs for the exception.

    "Rex" <> wrote in message
    news:biahed$78nne$-berlin.de...
    > It says JasperException ...
    >
    >
     
    Andy Flowers, Aug 24, 2003
    #5
  6. Rex

    Andy Flowers Guest

    Put them into web.xml as application parameters.

    See http://edocs.bea.com/wls/docs61/webapp/web_xml.html#1014756


    "Rex" <> wrote in message
    news:biahgl$75521$-berlin.de...
    > Also..do u know where one should put files that the application loads? I
    > have stored database settings in a text file. I put it in the /bin folder,
    > the application folder, and its Webinf folder, but it says file not
    > found..(i tried this after the jasper exception problem)
    > "Andy Flowers" <> wrote in message
    > news:eek:F32b.2342$...
    > > What is the exception ?
    > >
    > > "Rex" <> wrote in message
    > > news:biafbu$78agv$-berlin.de...
    > > > Im running Tomcat 4.1 with JDK 1.4.2 on Win XP SP1
    > > > I have made a simple database search page (using MSAccess) that

    fetches
    > > > records using jdbc odbc drivers.
    > > > A servlet does the database processing, puts the finished search

    results
    > > > into a vector (each result is represented by a javabean) and i use

    the
    > > > following code in doPost():
    > > >
    > > > session.setAttribute("results",l_vecTmp); // l_vecTmp is the vector
    > > > ServletConfig sc=getServletConfig();
    > > > ServletContext sx=sc.getServletContext();
    > > > RequestDispatcher rd=sx.getRequestDispatcher("/results.jsp");
    > > > rd.forward(req, res); //the 2 params are the standard httpservlet

    > > request
    > > > and response objects that were passed to the servlet
    > > >
    > > > In the JSP, I use the following code:
    > > > <%! int i;
    > > > Vector l_vecTmp;%>
    > > >
    > > >
    > > > <%! SearchResultBean l_srb;
    > > > int l_iSize=l_vecTmp.size(); %>
    > > > <% try
    > > > {
    > > > l_vecTmp=(Vector)request.getAttribute("results");
    > > > }
    > > > catch(Exception e)
    > > > {
    > > > e.printStackTrace();
    > > > }
    > > > %>
    > > >
    > > > The directory structure is as follows-
    > > > Location of results.jsp:
    > > > <tomcat-root>\webapps\studentsearch
    > > > Location of servlet:
    > > > <tomcat-root>\webapps\studentsearch\WEB-INF\classes
    > > >
    > > > When I run the application, I get a JasperException in the servlet, at

    > the
    > > > requestdispatcher line.
    > > > Does it mean the servlet cant find the JSP?
    > > > Do i have to add the JSP to the web.xml deployment descriptor?
    > > >
    > > > ANy help appreciated
    > > >
    > > > Rex
    > > >
    > > >

    > >
    > >

    >
    >
     
    Andy Flowers, Aug 24, 2003
    #6
  7. Rex

    Rex Guest

    Here's the exception stack trace

    org.apache.jasper.JasperException
    at
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:2
    48)
    at
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:289)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:240)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at
    org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.
    java:684)
    at
    org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatch
    er.java:432)
    at
    org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher
    ..java:356)
    *******************
    at
    com.rex.studentsearch.SearchServlet.doPost(SearchServlet.java:169)====> This
    is where I'm doing 'getRequestDispatcher.forward()'
    ********************
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at
    org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java
    :458)
    at
    org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.java:216)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    at
    org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
    FilterChain.java:247)
    at
    org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
    ain.java:193)
    at
    org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
    va:260)
    at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
    eNext(StandardPipeline.java:643)
    at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at
    org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

    at
    org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.ja
    va:191)
    at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
    eNext(StandardPipeline.java:643)
    at
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase
    ..java:471)
    at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
    eNext(StandardPipeline.java:641)
    at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at
    org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

    at
    org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2396)
    at
    org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180
    )
    at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
    eNext(StandardPipeline.java:643)
    at
    org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.
    java:170)
    at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
    eNext(StandardPipeline.java:641)
    at
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172
    )
    at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
    eNext(StandardPipeline.java:641)
    at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at
    org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

    at
    org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java
    :174)
    at
    org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invok
    eNext(StandardPipeline.java:643)
    at
    org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
    at
    org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)

    at
    org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
    at
    org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:405)
    at
    org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConne
    ction(Http11Protocol.java:380)
    at
    org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:508)
    at
    org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
    a:533)
    at java.lang.Thread.run(Thread.java:534)
     
    Rex, Aug 24, 2003
    #7
  8. Rex

    Rex Guest

    I have packaged my classes, and put them where you mentioned. The bean and
    servlet belong to the same package.(com.rex.studentsearch)
    The JasperException is thrown when I forward the request from the servlet to
    a JSP page. The servlet executes the database query (on Access, using the
    odbc bridge), puts the results into a vector, adds it to the HttpSession,
    and then calls getRequestDispatcher().forward() with the jsp as the target.
    I separated the code into separate method invocations-
    ServletConfig sc=getServletConfig();
    ServletContext sx=sc.getServletContext();
    RequestDispatcher rd=sx.getRequestDispatcher("/results.jsp");
    rd.forward(req, res); --->This is where the exception is thrown.
    The JSP compiled without problems the first time round.

    Perhaps the path to the JSP is wrong? It is placed in the application
    folder, in this case webapps/studentsearch.
    So i suppose the correct invocation would be ./results.jsp, relative to
    studentsearch
     
    Rex, Aug 24, 2003
    #8
    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. Sean Clarke
    Replies:
    1
    Views:
    1,901
    Sudsy
    Jan 7, 2004
  2. circuit_breaker
    Replies:
    2
    Views:
    2,021
    Jack Jia
    Apr 4, 2004
  3. Doug McCann
    Replies:
    1
    Views:
    1,045
    William Brogden
    Aug 5, 2004
  4. Replies:
    0
    Views:
    849
  5. javadev
    Replies:
    5
    Views:
    12,941
    javadev
    Nov 16, 2006
Loading...

Share This Page