You are viewing a plain text version of this content. The canonical link for it is here.
Posted to taglibs-user@tomcat.apache.org by David Treves <dw...@macam98.ac.il> on 2001/03/28 14:03:24 UTC
including servlets in a customed tag
Hi,
I am trying to include a servlet while processing a tag I wrote, I don't need specifically the request and response of the pageContext of that tag. I tried to include the servlet with new and with the existing request/response, both way the servlet simply was not included. it looks like it simply skips the including line.
the tag code is:
try{
ServletRequest request = pageContext.getRequest();
request.setAttribute("recipientId",userId); // add an attribute to be passed to the included file
ServletResponse response = pageContext.getResponse();
System.out.println("in tag");
javax.servlet.RequestDispatcher rd = pageContext.getRequest().getRequestDispatcher("/courses/servlet/cacheUsers");
rd.include(request, response);
System.out.println("after including (in tag)");
}
catch(javax.servlet.ServletException e){
System.out.println("ServletException: " + e.getMessage());
}
As you can see there are System outs and both of them printed. (the code was taken from the doEndTag())
Any idea whats wrong here?
Thanks!
David.
Re: including servlets in a customed tag
Posted by Pierre Delisle <pi...@sun.com>.
> David Treves wrote:
>
> Hi,
>
> I am trying to include a servlet while processing a tag I wrote, I don't
> need specifically the request and response of the pageContext of that tag. I
> tried to include the servlet with new and with the existing request/response,
> both way the servlet simply was not included. it looks like it simply skips
> the including line.
>
> the tag code is:
>
> try{
> ServletRequest request = pageContext.getRequest();
> request.setAttribute("recipientId",userId); // add an attribute to be passed
> to the included file
>
> ServletResponse response = pageContext.getResponse();
> System.out.println("in tag");
> javax.servlet.RequestDispatcher rd =
> pageContext.getRequest().getRequestDispatcher("/courses/servlet/cacheUsers");
> rd.include(request, response);
> System.out.println("after including (in tag)");
> }
> catch(javax.servlet.ServletException e){
> System.out.println("ServletException: " + e.getMessage());
> }
>
> As you can see there are System outs and both of them printed. (the code was
> taken from the doEndTag())
>
> Any idea whats wrong here?
Try
pageContext.include("/courses/servlet/cacheUsers");
instead of
rd.include(...)
-- Pierre