'jsp encoding display issue
I am finding a issue where the data is encoded properly in the controller and compiled jsp
, but is not displaying properly within an alert statement (or on the page). Please see the following configurations.
- tomcat server property
-Dfile.encoding=UTF8
- java controller - hard coded value
renderRequest.setAttribute("general", "¯_(ツ)_/¯ ¯_(ツ)_/¯");
- first line in jsp
<%@ page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
- jsp scriptlet to display session attribute
<%
String general = (String)request.getAttribute("general");
System.out.println("#### general is: " + general);
%>
#### general is: ¯_(ツ)_/¯ ¯_(ツ)_/¯
- html in jsp
<p>¯_(ツ)_/¯ ¯_(ツ)_/¯</p>
<pre>'<%= request.getAttribute("general") %>'</pre>
- compiled jsp snippet showing encoded chars
out.write("\t\t<p>¯_(ツ)_/¯ ¯_(ツ)_/¯</p>\r\n");
- all display
¯_(ツ)_/¯ ¯_(ツ)_/¯
- web.xml configuration
<filter>
<filter-name>setCharacterEncodingFilter</filter-name>
<filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<async-supported>true</async-supported>
</filter>
- server.xml configuration
<Connector URIEncoding="UTF-8" connectionTimeout="20000" port="7070" protocol="HTTP/1.1" redirectPort="8443"/>
What sort of simple configuration am I missing here?
Solution 1:[1]
It was a simple oversight to also include the filter-mapping along with the filter (slaps forehead). Added the following to the web.xml config along with the previous updates and all worked.
<filter-mapping>
<filter-name>setCharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |