aspose file tools*
The moose likes Servlets and the fly likes Can a servlet be embedded in another servlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Can a servlet be embedded in another servlet?" Watch "Can a servlet be embedded in another servlet?" New topic
Author

Can a servlet be embedded in another servlet?

chad stevens
Ranch Hand

Joined: Aug 20, 2002
Posts: 88
Hello.
Can a servlet be embedded in another servlet? If so, how?
CHAD
Avi Abrami
Ranch Hand

Joined: Oct 11, 2000
Posts: 1135

Hi Chad,
I'm interpreting your question as:
"Can a servlet be defined as an instance member of another servlet?"
I haven't tried it (have you?), but I imagine that there shouldn't be any problem doing that.
I assume you have some problem you are trying to solve and you think this "embedding servlets" thing is the way to go. Frankly, I can't think of a situation where you would need to do this (and that's why I've never tried it), so perhaps you could explain about the problem you are trying to solve -- because there's probably a better way to solve it -- rather than asking if your proposed solution is feasible.
Hope this helps you.
Good Luck,
Avi.
Paul Done
Greenhorn

Joined: Jan 03, 2003
Posts: 22
If you mean 'can the output of one servlet be included in the output of another servlet?' then the answer is yes. Like JSPs, your servlet can do a 'request dispatch include' to include the output of another servlet. Check the javadoc for ServletContext.getRequestDispatcher().
Paul
chad stevens
Ranch Hand

Joined: Aug 20, 2002
Posts: 88
Avi and Paul, thanks for your answers. This question was an interview question that I could not answer, another was can a servlet be embedded in JSP pages? I haven't worked with these items I know as far as what Paul did describe.
Thanks for the responses.
David Hibbs
Ranch Hand

Joined: Dec 19, 2002
Posts: 374
The correct answer is
"Define what you mean by 'embedded' -- do you mean the result content, or the servlet itself?"
Sounds like a pointy-hair question rather than a technical one, although perhaps he was trying to avoid using the word "include" to avoid giving a hint.


"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
chad stevens
Ranch Hand

Joined: Aug 20, 2002
Posts: 88
Hello David, he probably did mean include.. can you do this? Include a servlet in another?
 
 
subject: Can a servlet be embedded in another servlet?