Prevent IllegalStateException during redirect

On Glassfish 3.1.2.2 in case of an redirect you get a 
java.lang.IllegalStateException: PWC3990: getWriter() has already been called for this response
	at org.apache.catalina.connector.Response.getOutputStream(Response.java:674)
	at org.apache.catalina.connector.ResponseFacade.getOutputStream(ResponseFacade.java:206)

First check if response is already commited before accessing the stream.