...
- Ensure pageEncoding of all JSP views is UTF-8. (This is the default for most if not all views packaged with CAS)
Code Block <%@ page pageEncoding="UTF-8" %>
- Ensure the Content-Type header specifies UTF-8 encoding:
Code Block <%@ page contentType="text/html; charset=UTF-8" %> ... <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> ... </head> ...
- Set the character set encoding to UTF-8 for both the request and response as early in the processing stage as possible. The most convenient solution for this is defining a servlet filter that sets HttpServletRequest#setCharacterEncoding() and HttpServletResponse#setCharacterEncoding() to UTF-8. The following example uses CharacterEncodingFilter, which is a convenient choice that is actively maintained and well-documented.
Code Block <!-- This filter should be placed at the head of the filter chain, if possible, to ensure that all downstream filters have the proper encoding. --> <filter> <filter-name>CharacterEncodingFilter</filter-name> <filter-class>edu.vt.middleware.servlet.filter.CharacterEncodingFilter</filter-class> <!-- Sets the character encoding of the request to the given Java character set name. Name must be understood by java.nio.charset.Charset class, e.g., ISO-8859-1, UTF-8, UTF-16. --> <init-param> <param-name>requestCharsetName</param-name> <param-value>UTF-8</param-value> </init-param> <!-- Sets the character encoding of the response to the given Java character set name. Name must be understood by java.nio.charset.Charset class, e.g., ISO-8859-1, UTF-8, UTF-16. --> <init-param> <param-name>responseCharsetName</param-name> <param-value>UTF-8</param-value> </init-param> </filter>
- Set the scope of the character set filter according to your needs. The scope should be no larger than needed to avoid unintended side effects of character set encoding; however, it may be necessary to scope the entire application in many cases.
Code Block xml xml <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/**</url-pattern> </filter-mapping>
- Set the scope of the character set filter according to your needs. The scope should be no larger than needed to avoid unintended side effects of character set encoding; however, it may be necessary to scope the entire application in many cases.
Code Block xml xml <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/**</url-pattern> </filter-mapping>