aspose file tools*
The moose likes Servlets and the fly likes Calling a servlet from within another servlet without Struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Calling a servlet from within another servlet without Struts" Watch "Calling a servlet from within another servlet without Struts" New topic
Author

Calling a servlet from within another servlet without Struts

L Duperval
Ranch Hand

Joined: May 14, 2003
Posts: 63
This may be an easy question... I am working with Websphere 7.0, in case it matters.

I am creating a series of servlets which process XML documents. For eaxh XSD I have a different servlet. So, from a client perspective, you need to know the type of data you are working with in order to call the correct servlet to do the work. I want to avoid this.

So, I created a new servlet, whose task is to analyze the incoming XML and call the proper servlet to do the actual work. So, one point of contact for the client.

My problem is that the way I implemented it (using reflection), I have to manage the servlet's life cycle, which I don't want to.

After thinking about it, I realize there are (at least) two ways to do this:

  • Redirect the requestoto the proper servlet, using a new GET
  • Ask Websphere to return an (existing) instance of the proper servlet and call its doGet() method appropriately
  • Something else?

  • Any ideas or Web pages I should look at to figure how to to this?

    Thanks,

    L


    Live Free, Live Happy
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61654
        
      67

    How about a simple forward?


    [Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61654
        
      67

    By the way, the pattern you are describing is called Front Controller. You might want to read this article.
    L Duperval
    Ranch Hand

    Joined: May 14, 2003
    Posts: 63
    For some reason, I thought I needed to have a framework in place (such as Struts) to use forwarding. I'm looking into it.

    Thanks for the theoretical background.

    L
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61654
        
      67

    Nope, no framework required. Just use the RequestDispatcher.
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: Calling a servlet from within another servlet without Struts