首先-根据您的描述,听起来您想使用requestDispatcher.include而不是requestDispatcher.forward.
关于响应内容的包含,传递给requestDispatcher.include调用的响应可能是您自己创建的对象,该对象会将其输出写入字符串,而不是将其返回给浏览器.遵循以下内容可能是合适的:
final ServletOutputStream outputStream = new ServletOutputStream() {
public void write(int b) throws IOException {
outputBuffer.append((char) b);
}
};
SlingHttpServletResponseWrapper responseWrapper = new SlingHttpServletResponseWrapper(response) {
public ServletOutputStream getOutputStream() {
return outputStream;
}
public PrintWriter getWriter() throws IOException {
return new PrintWriter(outputBuffer);
}
public SlingHttpServletResponse getSlingResponse() {
return super.getSlingResponse();
}
};
包含之后,outputStream.toString()应该提供资源请求执行的结果.