everdelightedone
101 1

Hello everybody! I got a legacy project (2016 year) with zul-pages. The problem is some pages issue "Page not found" with com.sun.org.apache.xerces.internal.impl.io.MalformedByteSequenceException: Invalid byte 2 of 2-byte UTF-8 sequence (...stack trace follows). I found out that problem arises only on pages with "И" symbol (Cyrillic Capital Letter I, unicode code is U+0418). So, if I replace "И" with & # x0418; (without spaces) on .zul page - it works. It looks strange because all other Cyrillic symbols are working without any problems. Zk version is 7.0.3, Tomcat version 8.0.27, OS Windows 10 1803 build 17134.48 with russian locale. Every zul-page has <?xml version="1.0" encoding="UTF-8"?> as a first line. Is it a ZK framework bug?

delete retag edit

Sort by » oldest newest most voted

cor3000
3967 1 7

To me it simply sounds like your file might not be encoded/saved correctly as UTF-8.

I tried it on zkfiddle and it works. Could be I tested not the exact case. So can you please add what's missing in case I forgot a detail, update the fiddle and provide the link here?

everdelightedone
101 1

Thank you for the answer! I am new to ZK and possibly don't understand something simple. The project I got have been uploaded from git repository and I run it with Netbeans IDE 8.2 under Apache Tomcat 8.0.27. I have tried to run project under different browsers (Chrome 66.0.3359.181 and Firefox 59.0.2). Maven snippet from pom.xml:

        <properties>
<zk.spring.version>3.0</zk.spring.version>
<zk.version>7.0.3</zk.version>
</properties>
<dependency>
<groupId>org.zkoss.theme</groupId>
<artifactId>sapphire</artifactId>
<version>${zk.version}</version> </dependency> <dependency> <groupId>org.zkoss.zk</groupId> <artifactId>zkplus</artifactId> <version>${zk.version}</version>
</dependency>

<dependency>
<groupId>org.zkoss.zk</groupId>
<artifactId>zkbind</artifactId>
<version>${zk.version}</version> </dependency> <dependency> <groupId>org.zkoss.zk</groupId> <artifactId>zhtml</artifactId> <version>${zk.version}</version>
</dependency>

<dependency>
<groupId>org.zkoss.zk</groupId>
<artifactId>zkspring-core</artifactId>
<version>${zk.spring.version}</version> </dependency> <dependency> <groupId>org.zkoss.zk</groupId> <artifactId>zkspring-security</artifactId> <version>${zk.spring.version}</version>
</dependency>


The first line in .zul file is

<?xml version="1.0" encoding="UTF-8"?>


I can open .zul in Notepad++ without any encoding problem with UTF-8 encoding. I also can see ploblem symbol in Netbeans editor. I don't understand how is it possible for every cyrillic symbol to work without any problem, but just one of them and only with uppercase case to fail. My .zul snippet:

        <south height="250px" splittable="true" minsize="250" collapsible="true" style="border-bottom: 0; border-left: 0; border-right: 0;"
autoscroll="true"
<grid width="100%" height="100%" style="border: 0">
<columns>
<column hflex="min"/> <column/>
</columns>
<rows>
<row>
<label value="Код"/>
<vlayout>
<textbox width="" value="@bind(newItem.code) @validator(vm.codeValidator,length='30')" disabled="@load(!vm.canEdit)"  hflex="1"/>
<label sclass="error" value="@bind(vmsgs['code'])"/>
</vlayout>
</row>
<row>
<label value="Имя"/>
<vlayout>
<label sclass="error" value="@bind(vmsgs['name'])"/>
</vlayout>
</row>
<row>
<label value="Описание"/>
<vlayout>
<label sclass="error" value="@bind(vmsgs['description'])"/>
</vlayout>
</row>
<row>
<label value="Цвет"/>
<vlayout>
value="@bind(newItem.color) @converter(vm.comboBoxSelectedItemConverter) @validator(vm.uniqueValidator,length='255')"
style="@bind((newItem.color eq null or c:trim(newItem.color) eq '') ? '' : c:cat('color: #',c:replace(c:substring(newItem.color, 1, 7), 'FFFFFF', '000000')))"/>
<label sclass="error" value="@bind(vmsgs['color'])"/>
</vlayout>
</row>
</rows>
</grid>
</groupbox>
</south>


(I can't insert a full .zul's text in my post, because it contains links I'm getting error "Your karma is insufficient to publish links, please remove the link and post again".) Problem symbol is in the row <label value="Имя"/> I run it under Windows 10. I tried it to run of two different computers (both with the same hardware and OS). Opening page results "Page not found: /zk/priority/workMode.zul" error message.

( 2018-06-07 20:19:50 +0800 )edit

cor3000
3967 1 7

I found this post in another forum which also has a problem around the "И" character:

https://www.java-forums.org/new-java/51981-problem-encoding-russian-text-between-utf-8-unicode.html

Could it be that your default OS encoding is other than UTF-8? You might have to run the Java process specifically with UTF-8?

According to this you can run your application server with the JVM parameter ...

-Dfile.encoding=UTF-8


... to set it explicitely.

everdelightedone
101 1

Thank your very much for your help! I have tried to set VM Option for Tomcat as -Dfile.encoding=UTF-8 and Dfile.encoding=UTF8. I've also tried to set environmental variable JAVA_OPTS as -Dfile.encoding=UTF8. But unfortunately, it's not working in my case. The code from your first link

class Basic
{
public static void main(String[] args) throws Exception
{
String s = "";
for(char ch=0x0410; ch<=0x044F; ch++)
s += ch;
System.out.println(s);
s = new String(s.getBytes("UTF-8"));
System.out.println(s);
s = new String(s.getBytes(), "UTF-8");
System.out.println(s);
}
}


is working good in my case and yields

АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя
АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя
АБВГДЕЖЗИЙКЛМНОПРСТУФХЦЧШЩЪЫЬЭЮЯабвгдежзийклмнопрстуфхцчшщъыьэюя

[hide preview]