1

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?

2
  • Do you have a <meta charset="utf-8"/> in your html <head> and is your JSP really saved as UTF-8 (text encoding)? Commented Mar 31, 2020 at 3:34
  • Thank you, yes sir. The Eclipse IDE is saved as UTF-8 in the Resource > Text file encoding properties and the following tag <meta content="text/html; charset=UTF-8" http-equiv="content-type"> is in the <head> of the jsp. Commented Mar 31, 2020 at 13:59

1 Answer 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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.