cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mike Engelhart <>
Subject Re: RequestDispatcher &
Date Thu, 03 Feb 2000 19:25:03 GMT
Donald Ball wrote:

> That sounds like a very nice way to handle 'web application' development.
> What sort of caveats do you run into when calling cocoon this way?
> - donald
None!  I originally ignored this method of development because I was
assuming that Cocoon was an application development environment (you can
tell I didn't read the opening line of the Cocoon docs :-))

Anyway, it really makes working with Cocoon so much easier at least for me.
Most of the business logic has nothing to do with displaying data and being
able to do something like this in my servlet code (this is obviously
contrived and totally simple but you'll get the idea):

SQLSelect sqlSelect = new SQLSelect();
List resultSet = sqlSelect.query(conn, sql);
RequestDispatcher rd = null;
if (resultSet.size() != 0)
    request.setAttribute("RESULTSET", resultSet);
    rd = request.getRequestDispatcher("/xsp/results.xsp.xml");
    request.setAttribute("ERROR", "No results returned from query");
    rd = request.getRequestDispatcher("/xsp/error.xsp.xml");
rd.forward(request, response);

and then the following in my XSP

    List resultSet = (List) request.getAttribute("RESULTSET");
    ...iterate through resultset generating XML
or if an error occured from above code:
<xsp:page ...>
        <H1><xsp:expr>(String) request.getAttribute("ERROR")</xsp:expr></H1>

This method also saves the memory hit of storing everything in HttpSession's
which can too easily be forgotten about and eat up all your memory!!
This way the request object gets freed up as soon as the request is finished
BTW, you're not limited by datatype as I'm sure you're aware, but you can
easily pass a JavaBean and just call it's accessor methods when generating
the XML in your XSP.

Regardless, this it the route I'm taking.  It is working great.  I'll keep
you posted if I run into any problems with it but it should work fine.  I've
built several Servlet/JSP web applications using this method of request
dispatching and haven't seen any problems.
Oh yeah, this requires at least JSDK 2.1 - I'm  using Apache/Mod_SSL/JServ


View raw message