Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Servlet-to-JSP using Tomcat 4.1

Reply
Thread Tools

Servlet-to-JSP using Tomcat 4.1

 
 
Rex
Guest
Posts: n/a
 
      08-24-2003
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


 
Reply With Quote
 
 
 
 
Andy Flowers
Guest
Posts: n/a
 
      08-24-2003
What is the exception ?

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



 
Reply With Quote
 
 
 
 
Rex
Guest
Posts: n/a
 
      08-24-2003
It says JasperException ...


 
Reply With Quote
 
Rex
Guest
Posts: n/a
 
      08-24-2003
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
newsF32b.2342$...
> What is the exception ?
>
> "Rex" <> wrote in message
> news:biafbu$78agv$...
> > 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
> >
> >

>
>



 
Reply With Quote
 
Andy Flowers
Guest
Posts: n/a
 
      08-24-2003
Take a look at the server logs for the exception.

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



 
Reply With Quote
 
Andy Flowers
Guest
Posts: n/a
 
      08-24-2003
Put them into web.xml as application parameters.

See http://edocs.bea.com/wls/docs61/weba...l.html#1014756


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

> >
> >

>
>



 
Reply With Quote
 
Rex
Guest
Posts: n/a
 
      08-24-2003
Here's the exception stack trace

org.apache.jasper.JasperException
at
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:2
4
at
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:289)
at org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:240)
at javax.servlet.http.HttpServlet.service(HttpServlet .java:853)
at
org.apache.catalina.core.ApplicationDispatcher.inv oke(ApplicationDispatcher.
java:684)
at
org.apache.catalina.core.ApplicationDispatcher.doF orward(ApplicationDispatch
er.java:432)
at
org.apache.catalina.core.ApplicationDispatcher.for ward(ApplicationDispatcher
..java:356)
*******************
at
com.rex.studentsearch.SearchServlet.doPost(SearchS ervlet.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.serveR equest(InvokerServlet.java
:45
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.in ternalDoFilter(Application
FilterChain.java:247)
at
org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterCh
ain.java:193)
at
org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.ja
va:260)
at
org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invok
eNext(StandardPipeline.java:643)
at
org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)

at
org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.ja
va:191)
at
org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invok
eNext(StandardPipeline.java:643)
at
org.apache.catalina.authenticator.AuthenticatorBas e.invoke(AuthenticatorBase
..java:471)
at
org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invok
eNext(StandardPipeline.java:641)
at
org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)

at
org.apache.catalina.core.StandardContext.invoke(St andardContext.java:2396)
at
org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:180
)
at
org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invok
eNext(StandardPipeline.java:643)
at
org.apache.catalina.valves.ErrorDispatcherValve.in voke(ErrorDispatcherValve.
java:170)
at
org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invok
eNext(StandardPipeline.java:641)
at
org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:172
)
at
org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invok
eNext(StandardPipeline.java:641)
at
org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)

at
org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java
:174)
at
org.apache.catalina.core.StandardPipeline$Standard PipelineValveContext.invok
eNext(StandardPipeline.java:643)
at
org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:480)
at
org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:995)

at
org.apache.coyote.tomcat4.CoyoteAdapter.service(Co yoteAdapter.java:223)
at
org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:405)
at
org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConne
ction(Http11Protocol.java:380)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(P oolTcpEndpoint.java:50
at
org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.jav
a:533)
at java.lang.Thread.run(Thread.java:534)


 
Reply With Quote
 
Rex
Guest
Posts: n/a
 
      08-24-2003
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Which JVM to use for Tomcat 5.0.28 and Tomcat 5.5.4? Katerina McLean Java 1 12-10-2004 10:55 PM
Tomcat 4.1.31 - huge count of webapps, Tomcat hangs up Martin Eberle Java 2 12-03-2004 07:10 PM
Tomcat Web application manager - Virtual host Tomcat 4.30 + Apache2 + JK2 connector with multi IPs Joe Java 0 07-12-2004 03:06 PM
Apache Tomcat 4.1.24: problem with Tomcat Administration link Christos Gravvanis Java 0 07-07-2004 05:21 PM
[TOMCAT] Tomcat crashes %=zerointeractive.it% Java 1 01-22-2004 12:08 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57