Hi,

I have a JSP with struts tags in it. I want to read its contents from the struts action class. I did it using RequestDispatcher.

I wrote the following code ..
======
// Creates a response wrapper object.
BufferedHttpResponseWrapper responseWrapper = new BufferedHttpResponseWrapper(response);

// Creates a requestDispatcher object.
ServletContext sc = request.getSession().getServletContext();
String url = response.encodeRedirectURL("/web/jsp/osf/ShowStaffingForm.jsp");
RequestDispatcher dispatcher = sc.getRequestDispatcher(url);
try {
dispatcher.include(request,responseWrapper);
} catch (Exception e) {
e.printStackTrace();
}
try {
String result = new String(responseWrapper.getOutput());
System.out.println("Result :: "+result);
} catch (Exception e) {
System.out.println("Exception occurring here...");
e.printStackTrace();
}

//This is the reponse wrapper class.
/*
* BufferedHttpResponseWrapper class
* *
*/
public class BufferedHttpResponseWrapper extends HttpServletResponseWrapper {

PrintWriter pw = null;
ByteArrayOutputStream baos = null;

public BufferedHttpResponseWrapper(HttpServletResponse response) {

super(response);
baos = new ByteArrayOutputStream();
pw = new PrintWriter(baos);
}

public PrintWriter getWriter() throws IOException {
return pw;
}

public String getOutput() {
pw.flush();
pw.close();
return baos.toString();
}

}

I get the jsp content in my log files, but I get an exception on the browser when I call this action.
Please note that when the JSP has simple HTML tags i get the content with _no_ exception. Even when the JSP contains some custom tags which I developed ,
then also there is no exception and I get the content. The problem is only when there is Struts tags in the JSP, though I get the content, I get the
exception on the browser.

The following is the exception:

================================================== ========

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Stream closed
org.apache.struts2.dispatcher.Dispatcher.serviceAc tion(Dispatcher.java:515)
org.apache.struts2.dispatcher.FilterDispatcher.doF ilter(FilterDispatcher.java:419)
org.apache.struts2.dispatcher.ActionContextCleanUp .doFilter(ActionContextCleanUp.java:99)
jcifs.http.NtlmHttpFilter.doFilter(NtlmHttpFilter. java:147)

root cause

java.io.IOException: Stream closed
org.apache.jasper.runtime.JspWriterImpl.ensureOpen (JspWriterImpl.java:203)
org.apache.jasper.runtime.JspWriterImpl.flushBuffe r(JspWriterImpl.java:113)
org.apache.jasper.runtime.JspWriterImpl.flush(JspW riterImpl.java:171)
org.apache.jasper.runtime.JspRuntimeLibrary.includ e(JspRuntimeLibrary.java:954)
org.apache.jasper.runtime.PageContextImpl.include( PageContextImpl.java:601)
org.apache.struts2.dispatcher.ServletDispatcherRes ult.doExecute(ServletDispatcherResult.java:119)
org.apache.struts2.dispatcher.StrutsResultSupport. execute(StrutsResultSupport.java:178)
com.opensymphony.xwork2.DefaultActionInvocation.ex ecuteResult(DefaultActionInvocation.java:348)
com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:253)
com.opensymphony.xwork2.interceptor.DefaultWorkflo wInterceptor.doIntercept(DefaultWorkflowIntercepto r.java:221)
com.opensymphony.xwork2.interceptor.MethodFilterIn terceptor.intercept(MethodFilterInterceptor.java:8 6)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:224)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:223)
com.opensymphony.xwork2.util.profiling.UtilTimerSt ack.profile(UtilTimerStack.java:455)
com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:221)
com.opensymphony.xwork2.validator.ValidationInterc eptor.doIntercept(ValidationInterceptor.java:150)
org.apache.struts2.interceptor.validation.Annotati onValidationInterceptor.doIntercept(AnnotationVali dationInterceptor.java:48)
com.opensymphony.xwork2.interceptor.MethodFilterIn terceptor.intercept(MethodFilterInterceptor.java:8 6)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:224)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:223)
com.opensymphony.xwork2.util.profiling.UtilTimerSt ack.profile(UtilTimerStack.java:455)
com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:221)
com.opensymphony.xwork2.interceptor.ConversionErro rInterceptor.intercept(ConversionErrorInterceptor. java:123)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:224)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:223)
com.opensymphony.xwork2.util.profiling.UtilTimerSt ack.profile(UtilTimerStack.java:455)
com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:221)
com.opensymphony.xwork2.interceptor.ParametersInte rceptor.doIntercept(ParametersInterceptor.java:186 )
com.opensymphony.xwork2.interceptor.MethodFilterIn terceptor.intercept(MethodFilterInterceptor.java:8 6)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:224)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:223)
com.opensymphony.xwork2.util.profiling.UtilTimerSt ack.profile(UtilTimerStack.java:455)
com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:221)
com.opensymphony.xwork2.interceptor.StaticParamete rsInterceptor.intercept(StaticParametersIntercepto r.java:105)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:224)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:223)
com.opensymphony.xwork2.util.profiling.UtilTimerSt ack.profile(UtilTimerStack.java:455)
com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:221)
org.apache.struts2.interceptor.CheckboxInterceptor .intercept(CheckboxInterceptor.java:83)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:224)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:223)
com.opensymphony.xwork2.util.profiling.UtilTimerSt ack.profile(UtilTimerStack.java:455)
com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:221)
org.apache.struts2.interceptor.FileUploadIntercept or.intercept(FileUploadInterceptor.java:207)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:224)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:223)
com.opensymphony.xwork2.util.profiling.UtilTimerSt ack.profile(UtilTimerStack.java:455)
com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:221)
com.opensymphony.xwork2.interceptor.ModelDrivenInt erceptor.intercept(ModelDrivenInterceptor.java:74)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:224)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:223)
com.opensymphony.xwork2.util.profiling.UtilTimerSt ack.profile(UtilTimerStack.java:455)
com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:221)
com.opensymphony.xwork2.interceptor.ScopedModelDri venInterceptor.intercept(ScopedModelDrivenIntercep tor.java:127)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:224)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:223)
com.opensymphony.xwork2.util.profiling.UtilTimerSt ack.profile(UtilTimerStack.java:455)
com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:221)
org.apache.struts2.interceptor.ProfilingActivation Interceptor.intercept(ProfilingActivationIntercept or.java:107)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:224)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:223)
com.opensymphony.xwork2.util.profiling.UtilTimerSt ack.profile(UtilTimerStack.java:455)
com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:221)
org.apache.struts2.interceptor.debugging.Debugging Interceptor.intercept(DebuggingInterceptor.java:20 6)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:224)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:223)
com.opensymphony.xwork2.util.profiling.UtilTimerSt ack.profile(UtilTimerStack.java:455)
com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:221)
com.opensymphony.xwork2.interceptor.ChainingInterc eptor.intercept(ChainingInterceptor.java:115)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:224)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:223)
com.opensymphony.xwork2.util.profiling.UtilTimerSt ack.profile(UtilTimerStack.java:455)
com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:221)
com.opensymphony.xwork2.interceptor.I18nIntercepto r.intercept(I18nInterceptor.java:143)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:224)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:223)
com.opensymphony.xwork2.util.profiling.UtilTimerSt ack.profile(UtilTimerStack.java:455)
com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:221)
com.opensymphony.xwork2.interceptor.PrepareInterce ptor.doIntercept(PrepareInterceptor.java:121)
com.opensymphony.xwork2.interceptor.MethodFilterIn terceptor.intercept(MethodFilterInterceptor.java:8 6)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:224)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:223)
com.opensymphony.xwork2.util.profiling.UtilTimerSt ack.profile(UtilTimerStack.java:455)
com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:221)
org.apache.struts2.interceptor.ServletConfigInterc eptor.intercept(ServletConfigInterceptor.java:170)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:224)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:223)
com.opensymphony.xwork2.util.profiling.UtilTimerSt ack.profile(UtilTimerStack.java:455)
com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:221)
com.opensymphony.xwork2.interceptor.AliasIntercept or.intercept(AliasInterceptor.java:123)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:224)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:223)
com.opensymphony.xwork2.util.profiling.UtilTimerSt ack.profile(UtilTimerStack.java:455)
com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:221)
com.opensymphony.xwork2.interceptor.ExceptionMappi ngInterceptor.intercept(ExceptionMappingIntercepto r.java:176)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:224)
com.opensymphony.xwork2.DefaultActionInvocation$2. doProfiling(DefaultActionInvocation.java:223)
com.opensymphony.xwork2.util.profiling.UtilTimerSt ack.profile(UtilTimerStack.java:455)
com.opensymphony.xwork2.DefaultActionInvocation.in voke(DefaultActionInvocation.java:221)
org.apache.struts2.impl.StrutsActionProxy.execute( StrutsActionProxy.java:50)
org.apache.struts2.dispatcher.Dispatcher.serviceAc tion(Dispatcher.java:504)
org.apache.struts2.dispatcher.FilterDispatcher.doF ilter(FilterDispatcher.java:419)
org.apache.struts2.dispatcher.ActionContextCleanUp .doFilter(ActionContextCleanUp.java:99)
jcifs.http.NtlmHttpFilter.doFilter(NtlmHttpFilter. java:147)

================================================== =======================


Could any one please help me with this.

Thanks
-D