public PrintWriter getWriter()
        throws java.io.IOException 
    {
        if (_outputState==DISABLED)
            return __nullServletWriter;
                                   
        if (_outputState!=NO_OUT && _outputState!=WRITER_OUT)
            throw new IllegalStateException();

        // If we are switching modes, flush output to try avoid overlaps.
        if (_out!=null)
            _out.flush();
        
        /* if there is no writer yet */
        if (_writer==null)
        {
            /* get encoding from Content-Type header */
            String encoding = _httpResponse.getCharacterEncoding();
            
            if (encoding==null)
            {
                if (_servletHttpRequest!=null)
                {
                    /* implementation of educated defaults */
                    String mimeType = _httpResponse.getMimeType();                
                    encoding = _servletHttpRequest.getServletHandler()
                    	.getHttpContext().getEncodingByMimeType(mimeType);
                }
                if (encoding==null)
                    encoding = StringUtil.__ISO_8859_1; 
                _httpResponse.setCharacterEncoding(encoding,true);
            }
            
            /* construct Writer using correct encoding */
            _writer = new ServletWriter(_httpResponse.getOutputStream(), encoding);
        }                    
        _outputState=WRITER_OUT;
        return _writer;
    }