webapp forwarding without web.xml

H

Henry Townsend

My question involves servlets but the answer may not be
servlet-specific, which is why I ask here.

I'm building an app based on the servlet API. I want it to be user
extensible, meaning in this case that they should be able to write their
own servlets. As long as they implement an interface I provide and stick
their servlet in the right place it should plug right in.

I have most of the infrastructure for this in place already. The
remaining problem has to do with the fact that after writing an
extension they must add the following to web.xml:

<servlet>
<servlet-name>foo</servlet-name>
<servlet-class>my.package.FooServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>foo</servlet-name>
<url-pattern>/myapp/foo</url-pattern>
</servlet-mapping>

There are many problems with asking users to modify web.xml, such as
documenting how and the likelihood of that configuration being
overwritten in an upgrade and the need to restart the server. Meanwhile,
there's already a convention that http://myapp/foo maps to the class
my.package.FooServlet; i.e. the application already "knows" all the
config data above.

So what I'm trying to do is set up a FrontServlet and map all URLs
matching /myapp/* to it. It would then parse the URL and see that the
command is "foo" and forward the request to FooServlet. If no such class
exists it catches the exception and reports the error. Again, I have
most of this in place. I'm sending everything to FrontServlet and
parsing the URL. So here I am in FrontServlet and I have a request
object and a response object and I know I have to pass them to
FooServlet.doGet() and that's where I'm stuck.

Possible solutions might be at the servlet API level; maybe I'm missing
something about URL patterns or forwarding. Or maybe it could be solved
at the Java level. In some languages (e.g. Perl) you would use "eval".
Perhaps in Java it would require reflection. Just looking for ideas or
solutions from anyone who's solved this before.

Thanks,
Henry Thompson
 
H

Henry Townsend

Henry said:
My question involves servlets but the answer may not be
servlet-specific, which is why I ask here...

Never mind, I worked something out involving Class.forName(). Works nicely.

HT
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top