Alex Moffat wrote:

> I wonder if anyone could help me out with the following situation.
>
> I want to have more than one servlet cooperate in processing a request. For
> example, say a user requests
>
> http://www.foo.com/gateway/prog?k=12345266&bar=baz+boop with possibly some
> other parameters in the body of the request
>
> then I want a servlet to handle this request. What this involves is working
> out from the value of k what page is wanted. I then want the url rewritten
> so that jsp gets a chance to handle it, something like
>
> http://www.foo.com/docs/test.jsp?k=12345266&bar=baz+boop with possibly some
> other parameters in the body of the request
>
> I believe I can do this with an external redirect but that will convert the
> request into a GET so that's not really what I want. From looking at the
> mod_jserv code it doesn't seem to handle a response code of 200 with a
> location header the same way mod_cgi does, i.e. it does not do an internal
> redirect. It looks possible to modify mod_jserv to do an internal redirect
> but I've not looked hard enough to see if it would work. Also, when mod_cgi
> does an internal redirect it throws away the message body (by setting
> content length to zero) and I may need that later.
>
> Is it possible to have one servlet call another, as this would solve my
> problem? What I'd then do is have the one invoked directly by mod_jserv
> perform its manipulations and then call the jsp serlvet.
>
> Anyway, anyone have any thoughts about how to do this? A sort of mod_rewrite
> with processing of the request happening at each step, but with output only
> produced by the last setp. Perhaps servlet chaning would help but I don't
> think that's supported by mod_jserv (I could switch to Jrun etc. but don't
> want to unless I have to).
>

The current version of Apache JServ is compliant with the 2.0 Servlet API,
which supports the ServletContext.getServlet() call.  This lets you, within the
first servlet, ask for an instance of the second servlet and then call its
service() method directly.  You are still going to have problems sharing the
request message body if you have already read it, unless you buffer the data
and create your own request object to pass to the second one.

This approach is not a good idea, because the 2.1 version of the Servlet API
has deprecated getServlet().  In a 2.1 xompliant servlet engine, the
RequestDispatcher provides the functionality you are looking for.  You can
either forward processing to the second servlet (i.e. servlet chaining) or
include the output of the second servlet (i.e. dynamic server side includes).
The current version of Apache JServ does not support this yet -- it is being
worked on.

In either scenario, trying to share the request body is not going to be
transparent, because the servlet engine lets you read it only once.  You might
consider using some other mechanism (such as a session) to share the
information from the request body between the two servlets.  Then, you can use
the redirect approach that works in either a 2.0 or a 2.1 compliant servlet
engine.

>
> Thanks
> Alex
>

Craig McClanahan




----------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
Archives and Other:  <http://www.working-dogs.com/>
Problems?:           [EMAIL PROTECTED]

Reply via email to