Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Calling a servlet from within another servlet without Struts

 
L Duperval
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 64702
    86
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    How about a simple forward?
     
    Bear Bibeault
    Author and ninkuma
    Marshal
    Pie
    Posts: 64702
    86
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    By the way, the pattern you are describing is called Front Controller. You might want to read this article.
     
    L Duperval
    Ranch Hand
    Posts: 63
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Pie
    Posts: 64702
    86
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Nope, no framework required. Just use the RequestDispatcher.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic