Hi,

I have a servlet where I try to include other resources (html files
mostly) like this (displayURI is a String with the name of the resource
to include):

CharResponseWrapper responseWrapper = new CharResponseWrapper(response);
RequestDispatcher rqd =
getServletContext().getRequestDispatcher(displayURI);
try {
    rqd.include(request, responseWrapper);
    out.write(responseWrapper.toString());
} catch (Exception e) {
    out.println(e);
}

CharResponseWrapper is a class I found in an article or tutorial about
filters on java.sun.com. It should function as a buffer to hold the
response or contents of the included resource, and it looks like this:

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class CharResponseWrapper extends HttpServletResponseWrapper {
    private CharArrayWriter output;

    public String toString() {
        return output.toString();
    }
    public CharResponseWrapper(HttpServletResponse response) {
        super(response);
        output = new CharArrayWriter();
    }
    public PrintWriter getWriter() {
        return new PrintWriter(output);
    }
}

It works perfectly when the included resource is an html file, but if it
is an xml file I get this:

java.lang.IllegalStateException: getWriter() has already been called for
this response

Why - and how do I avoid this ?

I'm running this on Tomcat 4, which normally generates a directory
listing when given the name of one of the directories below its webapp
directory. If I try to include that I don't get anything at all - not
even an exception...

I haven't tried to include the output from another servlet yet.

Thnx in advance
Claus Nielsen

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to