On 16.01.2020 10:36, Lmhelp1 wrote:
Hello,

Thank you for your answer.
Indeed, I have such a filter:

In "web.xml":
----------------------------------------------------------------------------------------
  <filter>
     <filter-name>EncodingFilter</filter-name>
<filter-class>com.[...].EncodingFilter</filter-class>
     <init-param>
<param-name>requestEncoding</param-name>
       <param-value>UTF-8</param-value>
     </init-param>
   </filter>
   <filter-mapping>
     <filter-name>EncodingFilter</filter-name>
     <url-pattern>/*</url-pattern>
   </filter-mapping>
----------------------------------------------------------------------------------------

The "doFilter()" method of the "EncodingFilter" class which implements "Filter":
----------------------------------------------------------------------------------------
     public void doFilter(ServletRequest  servletRequest,
                          ServletResponse servletResponse,
                          FilterChain     filterChain)
     throws IOException, ServletException
     {
         // Respect the client-specified character encoding
         // (see HTTP specification section 3.4.1)
         if(servletRequest.getCharacterEncoding() == null)
         {
servletRequest.setCharacterEncoding(ms_encoding);
         }

         // Set the default response content type and encoding
         servletResponse.setContentType("text/html; charset=" + 
Finals.S_CHARSET);
servletResponse.setCharacterEncoding(Finals.S_CHARSET);

         filterChain.doFilter(servletRequest, servletResponse);
     }
----------------------------------------------------------------------------------------

Commenting the line:
servletResponse.setContentType("text/html; charset=" + Finals.S_CHARSET);
doesn't solve the problem.
I still get the error:
----------------------------------------------------------------------------------------
The stylesheet http ://localhost/fr/css/fo.css was not loaded because itsMIME type, “text/html”, is not “text/css”.
----------------------------------------------------------------------------------------


Also note :
https://tomcat.apache.org/tomcat-9.0-doc/servletapi/javax/servlet/ServletResponse.html#setCharacterEncoding-java.lang.String-

says :

"...calling this method with the String of UTF-8 is equivalent with calling setContentType with the String of text/html; charset=UTF-8."

So, in the above, if you have just commented-out the line :

          servletResponse.setContentType("text/html; charset=" + 
Finals.S_CHARSET);

but you left the following line unchanged

 servletResponse.setCharacterEncoding(Finals.S_CHARSET);

then executing this line is equivalent to setting the content type to 
"text/html".
And this looks suspiciously like the error you are getting..

As another way of avoiding that problem, you may also want to change in web.xml 
:

>      <url-pattern>/*</url-pattern>

by something that applies *only* to HTML responses.




Best regards,
--
Léa


On 15/01/2020 5:09 PM, Niall Fitzpatrick wrote:
Hi Lea,

I experienced this problem not so long ago when we upgraded our Tomcat to a later version of 9. Basically we had a filter applied to requests which was supposed to set the encoding of the response to be UTF-8. However, it was also setting the content type to text/html.

Previous to the Tomcat upgrade it wasn't an issue. I found that in one of the Tomcat updates (can't remember which one) the logic of the default servlet was altered such that if the content type has already been set in the response it can't be set again further down stream. So my resolution was to remove the line that set the content type in our filter.

Something to check anyway as it took me some time to figure out what was 
happening.

Niall


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org

Reply via email to