4

To suppport all UTF-8 characters we have added in Servlet filter

servletResponse.setContentType("text/html; charset=" + "UTF-8");
servletRequest.setCharacterEncoding(servletResponse.getCharacterEncoding());

because of this it sets the content type as "text\html" for all file types and for css also and browser denies to load it css with error on browser as.

Resource interpreted as Stylesheet but transferred with MIME type text/html:

But above works in jboss 6 I tried setting

<servlet-container name="default">
    <jsp-config mapped-file="false" development="true"/>
    <websockets/>
    <mime-mappings>
        <mime-mapping name="css" value="text/css"/>
        <mime-mapping name="msi" value="application/x-msi"/>
    </mime-mappings>
</servlet-container>

in the standalone-full.xml but this does not work. How does it automatically identify the file content types?

happy
  • 2,550
  • 17
  • 64
  • 109
  • You don't need to do this - the default encoding is UTF-8. I'd remove it all as the server should figure it out for you. – stdunbar Aug 10 '17 at 17:25
  • @stdunbar if i remove this then it fails to save utf-8 character as it modifies that character to something else – happy Aug 19 '17 at 13:40

1 Answers1

1

Your servlet filter is really not the best answer to support all UTF-8 characters, as you noticed, this choice is weird but I will not discuss it because it is not your question.

So, if you need your servlet filter to not interact with other contents than text/html, just use a servlet filter url-pattern.

For instance, you could have a servlet filter definition like this:

<filter>
   <filter-name>MyServletFilter<filter-name>
   <filter-class>[...]</filter-class>
   <init-param>
       [...]
   </init-param>
</filter>

<filter-mapping>
   <filter-name>MyServletFilter</filter-name>
   <url-pattern>*.jsp</url-pattern>
</filter-mapping>

Of course, you need to check that this pattern complies with your directory structure and other means to access your dynamic text/html contents.

Therefore, resources like http://myserver.com/myapp/myservlet/staticcontent/file.xls will not be altered by your specific filter.

Alexandre Fenyo
  • 4,526
  • 1
  • 17
  • 24