Can anyone show me how to include a servlet within a tag? I wrote a custom tag and in the doEndTag() method I want to include a servlet. I tried doing this with a RequestDispatcher object, but it did not work.

Alessandro A. Garbagnati

You cannot use the include method of the RequestDispatcher ojbect inside a custom tag because the included servlet will be inserted directly into the response object, and this is not allowed during the execution of a custom tag.

A possible solution is to use a java.net.HttpURLConnection for executing a connection to the servlet, and retrieving the response.