webapp forwarding without web.xml

Discussion in 'Java' started by Henry Townsend, Sep 19, 2005.

  1. 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:



    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.

    Henry Thompson
    Henry Townsend, Sep 19, 2005
    1. Advertisements

  2. Henry Townsend wrote:
    > 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.

    Henry Townsend, Sep 20, 2005
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    S. Justin Gengo [MCP]
    Feb 10, 2006
  2. Henry Townsend
    Henry Townsend
    Oct 18, 2005
  3. Replies:
    Chris Smith
    Jun 2, 2006
  4. Andrew
    Jun 28, 2009
  5. Andrew Tomazos

Share This Page