Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Servlet-to-JSP using Tomcat 4.1

3 views
Skip to first unread message

Rex

unread,
Aug 24, 2003, 9:44:11 AM8/24/03
to
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

unread,
Aug 24, 2003, 10:06:56 AM8/24/03
to
What is the exception ?

"Rex" <thomas.ande...@matrix.net> wrote in message
news:biafbu$78agv$1...@ID-202120.news.uni-berlin.de...

Rex

unread,
Aug 24, 2003, 10:19:38 AM8/24/03
to
It says JasperException ...


Rex

unread,
Aug 24, 2003, 10:20:49 AM8/24/03
to
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" <notsu...@nowayhose.com> wrote in message
news:oF32b.2342$MS5....@newsfep4-glfd.server.ntli.net...

Andy Flowers

unread,
Aug 24, 2003, 10:33:49 AM8/24/03
to
Take a look at the server logs for the exception.

"Rex" <thomas.ande...@matrix.net> wrote in message

news:biahed$78nne$1...@ID-202120.news.uni-berlin.de...
> It says JasperException ...
>
>


Andy Flowers

unread,
Aug 24, 2003, 10:37:40 AM8/24/03
to
Put them into web.xml as application parameters.

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


"Rex" <thomas.ande...@matrix.net> wrote in message

news:biahgl$75521$1...@ID-202120.news.uni-berlin.de...

Wendy S

unread,
Aug 24, 2003, 10:45:57 AM8/24/03
to
Rex wrote:
> Im running Tomcat 4.1 with JDK 1.4.2 on Win XP SP1
> 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

Do you have any imports at the top of your jsp? Based on the fact that you
didn't package your Servlet class, I'm going to guess that you also did not
package your JavaBean.

Like the other people who responded, I'd like to see the *entire* error
message. I doubt that you're getting a JasperException from your Servlet.
Jasper is the engine that converts JSP to Java code and then compiles it.

There's not enough information in your post to be sure, but I suggest you
package your code, and place the .class files underneath 'WEB-INF/classes'
in a structure that matches the package structure. The default package (no
package statement) is only meant for testing and simple examples,
production code, or even moderately complex examples, needs to be packaged.

--
Wendy in Chandler, AZ

Rex

unread,
Aug 24, 2003, 11:34:20 AM8/24/03
to
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

unread,
Aug 24, 2003, 11:54:25 AM8/24/03
to
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


Andy Flowers

unread,
Aug 24, 2003, 12:53:00 PM8/24/03
to
Unfortunately the exception is just one of the standard ones that means the
JSP either couldn't be found, couldn't be compiled or has a severe error in
it. It looks as though the runtime is attempting to run the JSP OK so the
fault does not appear to be in the servlet.

Have you tried calling the JSP directly, via a simple request for
http://<site:port>/results.jsp

Does this work ?, you may need to alter the JSP to be defensive coded such
that it will not crash if it's assumptions (i.e. existence of a bean and the
contents of the said bean) are not met.

One common problem I have encountered is mis-spelling, the JSP name is case
sensitive. Is the JSP named results.jsp with a lower case r ?

If this works then the JSP is OK so you'd have to take a look at some other
causes such as logic errors in the JSP.

As to your other question, in another post, /results.jsp is the correct
invocation. The / means from the root of the web application.

"Rex" <thomas.ande...@matrix.net> wrote in message

news:bialqg$76c6n$1...@ID-202120.news.uni-berlin.de...

0 new messages