Servlet-to-JSP using Tomcat 4.1  
Author Message
Rex





PostPosted: 2003-8-24 21:44:00 Top

java-programmer, Servlet-to-JSP using Tomcat 4.1 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





PostPosted: 2003-8-24 22:07:00 Top

java-programmer >> Servlet-to-JSP using Tomcat 4.1 What is the exception ?

"Rex" <email***@***.com> wrote in message
news:biafbu$78agv$email***@***.com...
> 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





PostPosted: 2003-8-24 22:20:00 Top

java-programmer >> Servlet-to-JSP using Tomcat 4.1 It says JasperException ...


 
 
Rex





PostPosted: 2003-8-24 22:21:00 Top

java-programmer >> Servlet-to-JSP using Tomcat 4.1 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" <email***@***.com> wrote in message
news:oF32b.2342$email***@***.com...
> What is the exception ?
>
> "Rex" <email***@***.com> wrote in message
> news:biafbu$78agv$email***@***.com...
> > 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





PostPosted: 2003-8-24 22:34:00 Top

java-programmer >> Servlet-to-JSP using Tomcat 4.1 Take a look at the server logs for the exception.

"Rex" <email***@***.com> wrote in message
news:biahed$78nne$email***@***.com...
> It says JasperException ...
>
>


 
 
Andy Flowers





PostPosted: 2003-8-24 22:38:00 Top

java-programmer >> Servlet-to-JSP using Tomcat 4.1 Put them into web.xml as application parameters.

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


"Rex" <email***@***.com> wrote in message
news:biahgl$75521$email***@***.com...
> 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" <email***@***.com> wrote in message
> news:oF32b.2342$email***@***.com...
> > What is the exception ?
> >
> > "Rex" <email***@***.com> wrote in message
> > news:biafbu$78agv$email***@***.com...
> > > 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





PostPosted: 2003-8-24 23:34:00 Top

java-programmer >> Servlet-to-JSP using Tomcat 4.1 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





PostPosted: 2003-8-24 23:54:00 Top

java-programmer >> Servlet-to-JSP using Tomcat 4.1 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