Servlet-to-JSP using Tomcat 4.1

R

Rex

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
 
R

Rex

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

Rex

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

Rex

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top