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

Can a servlet be embedded in another servlet?

 
chad stevens
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello.
Can a servlet be embedded in another servlet? If so, how?
CHAD
 
Avi Abrami
Ranch Hand
Posts: 1141
1
Java Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
chad stevens
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello David, he probably did mean include.. can you do this? Include a servlet in another?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic