tags:

views:

147

answers:

1

Thanks to everyone in advance -

I have yet to find an easy way to do this but, is it possible to take over the handling of the data (headers and everything) written to JspWriter? Sort of like a liaison to manage that buffer dynamically and then control the output to JspWriter? I am running into issues with redirects where the status header is already being flushed out because of some of my includes (I think its the includes, but regardless its definitely flushing the buffer).

I am aware of setting buffer sizes etc.

I am not using a framework, just pure jsp on tomcat.

Thanks,

Sam

+3  A: 

You can try writing a Filter and mapping it to intercept your JSPs:

(excerpt from web.xml)
<filter>
  <filter-name>jspFilter</filter-name>
  <filter-class>com.mypackage.JspFilter</filter-class>
</filter>
<filter-mapping>
  <filter-name>jspFilter</filter-name>
  <url-pattern>*.jsp</url-pattern>
</filter-mapping>

In your doFilter() method implementation you can wrap the servlet response into your own by extending HttpServletResponseWrapper and overriding its getWriter() / getOutputStream() methods to use StringWriter to buffer the response. After you invoke doFilter() method and it returns (or throws an exception) you can do whatever you want with the buffered response - print it, redirect to another page, what have you.

ChssPly76
Thanks again for the response-I found this code, which i think sort of does what you are talking about:http://docstore.mik.ua/orelly/xml/jxslt/ch08_04.htm#javaxslt-CHP-8-EX-10Would I be able to do this overriding in the context of jsp (ie. <%! %>)?For instance:<filter> <filter-name>jspFilter</filter-name> <filter-class>jspfilter.jsp</filter-class></filter><filter-mapping> <filter-name>jspFilter</filter-name> <url-pattern>*.jsp</url-pattern></filter-mapping>Also, when does the doFilter() actually get invoked and where does that actually get placed?Thanks,Sam
Yes, `BufferedHttpResponseWrapper` in the above link does what I'm talking about. I'm not sure what you mean by "overriding in the context of jsp" - that you want to implement filter as JSP? That can't be done, it has to be a java class. There is an example (`MyFilter`) shown in your link, you can also look here: http://java.sun.com/javaee/5/docs/tutorial/doc/bnagb.htmlCompiled filter class has to be deployed as part of your web application (you can put it in /WEB-INF/classes), doFilter() method will be invoked automatically by servlet container (Tomcat).
ChssPly76
Thanks a lot for you help!
You're welcome, good luck with your project. Out of sheer curiosity - that link you've posted, was it a random google result or are you from Ukraine?
ChssPly76