Hi dear Users,

I have a requirement that I need to cofigure the language encoding based on the Request Header "accept-charset". If this is not available than we have our default charset. Now I am overriding the configureResponse() and NOT calling super.configureResponse(). But I am using the same lines used in the source code and please find the code used in configureResponse at the end of the posting. The problem I am facing is that when I visit the page through a wicket link I get the response output stream open in configureResponse, but when I refresh the page  the output stream opens after configureResponse is executed. As a result in the first case I get garbage character and in the second case I get correct ouput. Please advice what to do. Currently I am cofiguring the output stream to Shift_JIS hard codedly. If I can get this flow to work then dynamically I will read the request's "accept-charset" and set it. It is a bit urgent so quick response will be appreciated.

Thank you.

        final RequestCycle cycle = getRequestCycle();
        final Application application = cycle.getApplication();
        final Response response = cycle.getResponse();

        // Determine encoding
        final String encoding = application.getRequestCycleSettings().getResponseRequestEncoding();

        final String encoding1 = "text/" + getMarkupType() + "; charset=" + SHIFT_JIS;

        // Set content type based on markup type for page
        ( (WebResponse) response ).getHttpServletResponse().setCharacterEncoding( SHIFT_JIS );
        ( (WebResponse) response ).getHttpServletResponse().setContentType( encoding1 );
        ( (WebResponse) response ).getHttpServletResponse().setHeader( ACCEPT_CHARSET, SHIFT_JIS );
        ( (WebResponse) response ).getHttpServletResponse().setHeader( ACCEPT_LANGUAGE, JA_JP );
        // response.setContentType ("text/" + getMarkupType() + "; charset=" +
        // encoding);

        // Write out an xml declaration if the markup stream and settings allow
        final MarkupStream markupStream = findMarkupStream();
        if( ( markupStream != null ) && ( markupStream.getXmlDeclaration() != null )
                && ( application.getMarkupSettings().getStripXmlDeclarationFromOutput() == false ) )
            response.write( "<?xml version='1.0' encoding='" );
            response.write( SHIFT_JIS );
            response.write( "'?>" );
        System.out.println(( (WebResponse) response ).getHttpServletResponse().getCharacterEncoding());

        // Set response locale from session locale
        response.setLocale( getSession().getLocale() );

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
Wicket-user mailing list

Reply via email to