Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring and XSLT, character encoding
    primarykey
    data
    text
    <p>I have problem with proper charset encoding part of HTML view. XSL file in JSP files generates .html. Values from database are encoded correct, but static headers of table contain wrong characters.</p> <p>For example, there are headers named: Imię, Nazwisko, Hasło, Płeć, but it generates: ImiÄ™, Nazwisko, HasÅ‚o, PÅ‚eć</p> <p>My forHomeHtml.xml template:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns="http://www.w3.org/1999/xhtml" version="1.0"&gt; &lt;xsl:output method="xhtml" encoding="UTF-8" indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" /&gt; &lt;xsl:template match="/"&gt; &lt;xsl:apply-templates /&gt; &lt;/xsl:template&gt; &lt;xsl:template match="/employees"&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt;&lt;/th&gt; &lt;th&gt;Imię&lt;/th&gt; &lt;th&gt;Nazwisko&lt;/th&gt; &lt;th&gt;Hasło&lt;/th&gt; &lt;th&gt;Płeć&lt;/th&gt; &lt;/tr&gt; &lt;xsl:for-each select="./employee"&gt; &lt;tr&gt; &lt;td&gt;&lt;/td&gt; &lt;td&gt; &lt;xsl:value-of select="name/text()" /&gt; &lt;/td&gt; &lt;td&gt; &lt;xsl:value-of select="surname/text()" /&gt; &lt;/td&gt; &lt;td&gt; &lt;xsl:value-of select="password/text()" /&gt; &lt;/td&gt; &lt;td&gt; &lt;xsl:value-of select="gender/text()" /&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/xsl:for-each&gt; &lt;/table&gt; &lt;/xsl:template&gt; </code></pre> <p></p> <p>JSP site:</p> <pre><code>&lt;%@ taglib prefix="x" uri="http://java.sun.com/jsp/jstl/xml" %&gt; &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt; &lt;c:import var="inputDocument" url="http://localhost:8080/xyz/home.xml" /&gt; &lt;c:import var="stylesheet" url="/WEB-INF/xsl/forHomeHtml.xsl" /&gt; &lt;x:transform xml="${inputDocument}" xslt="${stylesheet}"&gt; &lt;/x:transform&gt; </code></pre> <p>I use Tiles, so the encoding is declared in main template:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt; &lt;%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%&gt; &lt;%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;&lt;tiles:getAsString name="title" /&gt;&lt;/title&gt; ... </code></pre> <p>I will add that I have encoding filter in web.xml</p> <pre><code>&lt;filter&gt; &lt;filter-name&gt;encodingFilter&lt;/filter-name&gt; &lt;filter-class&gt;org.springframework.web.filter.CharacterEncodingFilter&lt;/filter-class&gt; &lt;init-param&gt; &lt;param-name&gt;encoding&lt;/param-name&gt; &lt;param-value&gt;UTF-8&lt;/param-value&gt; &lt;/init-param&gt; &lt;init-param&gt; &lt;param-name&gt;forceEncoding&lt;/param-name&gt; &lt;param-value&gt;true&lt;/param-value&gt; &lt;/init-param&gt; &lt;/filter&gt; &lt;filter-mapping&gt; &lt;filter-name&gt;encodingFilter&lt;/filter-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/filter-mapping&gt; </code></pre> <p>Character encoding of files (JSP, XSL, XML, etc.) is setted to UTF-8. Character encoding of the browser is setted to UTF-8.</p> <p>Does anybody know the reason of that problem?</p> <hr> <p><strong>Update</strong>: It is strange, but the source of site contains following code:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Strona główna&lt;/title&gt; &lt;style type="text/css"&gt; .table-list { border: 1px solid black; border-collapse: collapse; } ... &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;table width="100%" border="0"&gt; &lt;tr style="background-color: #EEEEEE;"&gt; &lt;td&gt;&lt;?xml version="1.0" encoding="UTF-8" ?&gt; &lt;ul class="navigation_menu"&gt; &lt;li&gt;&lt;a href="./home.htm"&gt;Strona główna&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="./rejestracja.htm"&gt;Rejestracja&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="./historia-wypozyczen-samochodu.htm"&gt;Historia samochodu&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="./dodawanie-zamowienia.htm"&gt;Dodawanie zamówienia&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt; &lt;div style="text-align: center;"&gt; Liczba obsłużonych dzisiaj zamówień: 0 &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" align="left"&gt; &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE table PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1- transitional.dtd"&gt; &lt;table xmlns="http://www.w3.org/1999/xhtml" xmlns:xhtml="http://www.w3.org/1999/xhtml"&gt; &lt;tr&gt; &lt;th /&gt; &lt;th&gt;ImiÄ&amp;#153;&lt;/th&gt; &lt;th&gt;Nazwisko&lt;/th&gt; &lt;th&gt;HasÅ&amp;#130;o&lt;/th&gt; &lt;th&gt;PÅ&amp;#130;eÄ&amp;#135;&lt;/th&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td /&gt; &lt;td&gt;Zenon&lt;/td&gt; &lt;td&gt;Kowalski&lt;/td&gt; &lt;td&gt;zHasło&lt;/td&gt; &lt;td&gt;Mężczyzna&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td /&gt;&lt;/tr&gt; .... &lt;tr style="background-color: #EEEEEE;"&gt; &lt;td&gt;&lt;?xml version="1.0" encoding="UTF-8" ?&gt; &lt;div style="text-align: center;"&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>There's no content-type header!</p> <p>Should I change my Tiles template?</p> <p>Btw, @Alejandro, @Jim Garrison - thanks for tips.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload