You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Christian Cryder <ch...@lutris.com> on 2000/09/28 00:40:03 UTC

Q about RequestDispatcher

Hi folks,

My question is this: With the removal of ServletContext.getContext(), it
looks like the only way to dispatch a req to a servlet is to use the
RequestDispatcher interface. Is this correct? If so, here's my problem...

I'm looking for a way to forward requests to servlets which are implemented
as inner classes. There is no way to do this through the RequestDispatcher
interface, because it will not be able to find/instantiate the inner class
implementation.

Now, I _can_ instantiate the inner classes myself (ie. whenever the parent
servlet that contains them is instantiated) and then just invoke the
service() method on them, but I have a feeling that I should really be going
through the RequestDispatcher.

So...

1. What are the implications of invoking service() directly instead of going
through the RequestDispatcher?

2. What would it take to make it possible for RequestDispatcher to find
inner class instances that implement Servlet?

3. Is ther any mechanism to provide a custom RequestDispatcher which could
find/dispatch to inner classes?

4. Do you have any other suggestions as to how I might be able to invoke
inner classes that implement the Servlet interface?

As to why I'm trying to do this in the first place: I'm experimenting with
an event handling framework, and am trying to see if I can mirror the 1.1
event model used by Swing, where inner classes are used extensively.

Thanks much,
Christian
------------------------------------------------
Christian Cryder
Software Engineer, Rocks
Lutris Technologies, Inc.
christianc@lutris.com
------------------------------------------------
       "What a great time to be a Geek"
------------------------------------------------
 http://www.lutris.com ~ http://xmlc.enhydra.org



Re: Q about RequestDispatcher

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.
Christian Cryder wrote:

> Hi folks,
>
> My question is this: With the removal of ServletContext.getContext(), it
> looks like the only way to dispatch a req to a servlet is to use the
> RequestDispatcher interface. Is this correct? If so, here's my problem...
>
> I'm looking for a way to forward requests to servlets which are implemented
> as inner classes. There is no way to do this through the RequestDispatcher
> interface, because it will not be able to find/instantiate the inner class
> implementation.
>
> Now, I _can_ instantiate the inner classes myself (ie. whenever the parent
> servlet that contains them is instantiated) and then just invoke the
> service() method on them, but I have a feeling that I should really be going
> through the RequestDispatcher.
>
> So...
>
> 1. What are the implications of invoking service() directly instead of going
> through the RequestDispatcher?
>
> 2. What would it take to make it possible for RequestDispatcher to find
> inner class instances that implement Servlet?
>
> 3. Is ther any mechanism to provide a custom RequestDispatcher which could
> find/dispatch to inner classes?
>
> 4. Do you have any other suggestions as to how I might be able to invoke
> inner classes that implement the Servlet interface?
>
> As to why I'm trying to do this in the first place: I'm experimenting with
> an event handling framework, and am trying to see if I can mirror the 1.1
> event model used by Swing, where inner classes are used extensively.
>

I think one of the issues is going to be that you need a public constructor for
the servlet container to instantiate a servlet class dynamically, and inner
classes probably don't have one.

When looking at what you're trying to do, is there a particular reason that
event handlers have to be servlets?  What about routing all the requests through
a controller servlet that instantiates event handler instances of some
appropriate class as needed (based on the request URI or whatever)?  These
handlers could be inner classes of the controlling servlet, or they could be
standard top level classes.

This approach is pretty much what "model 2" oriented frameworks (like Struts)
do.

>
> Thanks much,
> Christian
>

Craig McClanahan

====================
See you at ApacheCon Europe <http://www.apachecon.com>!
Session VS01 (23-Oct 13h00-17h00):  Sun Technical Briefing
Session T06  (24-Oct 14h00-15h00):  Migrating Apache JServ
                                    Applications to Tomcat