Re: How to pass an empty contentCharset to streamResult

"Ing. Andrea Vettori" <[email protected]> Fri, 2 Jan 2026 16:14:45 +0100
Newsgroups gmane.comp.jakarta.struts.devel
Message-ID <[email protected]>
Thanks I will create the JIRA ticket.
However I don’t understand your answer about my first question.
What is the cause I always find the charset even if it’s not specified as a parameter ? For example if content type is application/pdf served from StreamResult I find it adds the charset even with no charset parameter on the struts.xml.

Thank you!

> On 2 Jan 2026, at 16:06, Lukasz Lenart <[email protected]> wrote:
> 
> wt., 30 gru 2025 o 12:56 Ing. Andrea Vettori <[email protected]> napisał(a):
>> 
>> Hello,
>> I’m facing an issue and I think it’s a “bug” on StreamResult (not sure about it however).
>> 
>> I know I can pass or do not pass a parameter contentCharSet on the result in struts.xml. If I do not pass it, for some reason I find UTF-8 is added automatically.
>> 
>> However if I do pass a value that is an expression I would expect that if the expression evaluates to null, the charset would not be added to the headers.
>> What happens instead is that a
>> 
>> ;charSet=
>> 
>> string is added to the content type.
>> 
>> The “bug” is likely related to this code in StreamResult.java
>> 
>>            if (contentCharSet != null && !contentCharSet.isEmpty()) {
>>                oResponse.setContentType(conditionalParse(contentType, invocation) + ";charset=" + conditionalParse(contentCharSet, invocation));
>>            } else {
>>                oResponse.setContentType(conditionalParse(contentType, invocation));
>>            }
> 
> This looks like a bug, feel free to register a JIRA ticket.
> 
>> So my questions are :
>> 
>> 1. why I find UTF-8 if I don’t specify the parameter;
>> 2. shouldn’t the if check the emptiness of the evaluated expression in the code above ?
> 
> Also the "struts.i18n.encoding" and Dispatcher#prepare() method can be
> problematic, depending on your servlet container. Maybe we should
> always forcefully set character encoding in a result to reset the
> default behaviour. Please register a ticket and I can work on a
> solution.
> 
> 
> Cheers
> Łukasz
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>