You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Marcin Jaskuła <ja...@expro.pl> on 2001/08/20 20:39:24 UTC

Problem with page encoding for ISO-8859-2

Hi,

I have change my JSP server form JServ to Tomcat (v. 3.2.3-1) recently and
found several problems with page encoding.
I have looked into the archive and found a lot of mails about the problem
but no simple solutions.

The problems are:

1. Compilation problem:
I wrote some simple jsp page, which consists of some polish character:

<%@ page contentType="text/html; charset=iso-8859-2" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-2">
</head>
<body>
ą
</body>
</html>

The server crashes with error 500:

Internal Servlet Error:

org.apache.jasper.JasperException: Unable to compile class for JSP
Found 1 semantic error compiling "_0002fa_0002ejspa_jsp_0.java":

    56.                 out.write("\n\n\n\n\n\n\n\u00-$\u00)%
<----------\n\n\n");

*** Error: The value of this "String" literal is invalid. Perhaps it
contains a bad escape sequence?

If I change "ą" to "a" it works !
In my opinion the characters are translated to the Unicode in wrong way.

2. I cannot get proper values from the forms. When I use
request.getParameter() method I get different characters then I write into
form's fields (returned characters depend on the "page contentType" value
but always are wrong).

3. When I try to print some data from a database I get wrong characters in
the output !


The best solution is to turn off all encoding of IO streams and before
compilation of the jsp page. Maybe somebody has done it already or there is
some other method to solve the problems.

Bye
	Marcin



RE: Problem with page encoding for ISO-8859-2

Posted by Marcin Jaskuła <ja...@expro.pl>.
>Most of the time I use:
><%@ page buffer="16kb" contentType="text/html; charset=iso-8859-2"
>pageEncoding="iso-8859-2" autoFlush="false" %>
>As far as I know it's the "pageEncoding" that matters, and "contentType" is
>only used for specifing what is send in "Content-type:" HTTP header. So, in
>non-english page it makes no sense to use only one, you have to set both.
>

I use Tomcat 3.2.3 and <%@page pageEncoding="..." %> is invalid attribute in
this version.
Unfortunately I cannot change server version to 4.0

Bye, Marcin


RE: Problem with page encoding for ISO-8859-2

Posted by Deacon Marcus <de...@wwtech.pl>.
Hi,

> From: Marcin Jaskuła [mailto:jaskula@expro.pl]
> Sent: Monday, August 20, 2001 8:39 PM
>
> Hi,
>
> I have change my JSP server form JServ to Tomcat (v. 3.2.3-1) recently and
> found several problems with page encoding.
> I have looked into the archive and found a lot of mails about the problem
> but no simple solutions.
>
> The problems are:
>
> 1. Compilation problem:
> I wrote some simple jsp page, which consists of some polish character:
>
> <%@ page contentType="text/html; charset=iso-8859-2" %>

Most of the time I use:
<%@ page buffer="16kb" contentType="text/html; charset=iso-8859-2"
pageEncoding="iso-8859-2" autoFlush="false" %>
As far as I know it's the "pageEncoding" that matters, and "contentType" is
only used for specifing what is send in "Content-type:" HTTP header. So, in
non-english page it makes no sense to use only one, you have to set both.

> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
I'm not 100% positive on that one, but I think this line should be the first
line in file, and it won't be - if you have end of line after a directive,
you get empty line and this is send as second line.

> <html>
> <head>

> <meta http-equiv="content-type" content="text/html; charset=iso-8859-2">
Redundant - that's what was set in Page directive.

> </head>
> <body>
> ą
> </body>
> </html>
>
> The server crashes with error 500:
>
> Internal Servlet Error:
>
> org.apache.jasper.JasperException: Unable to compile class for JSP
> Found 1 semantic error compiling "_0002fa_0002ejspa_jsp_0.java":
>
>     56.                 out.write("\n\n\n\n\n\n\n\u00-$\u00)%
> <----------\n\n\n");
>
> *** Error: The value of this "String" literal is invalid. Perhaps it
> contains a bad escape sequence?
>
> If I change "ą" to "a" it works !
> In my opinion the characters are translated to the Unicode in wrong way.
>
> 2. I cannot get proper values from the forms. When I use
> request.getParameter() method I get different characters then I write into
> form's fields (returned characters depend on the "page contentType" value
> but always are wrong).
>
> 3. When I try to print some data from a database I get wrong characters in
> the output !
>
>
> The best solution is to turn off all encoding of IO streams and before
> compilation of the jsp page. Maybe somebody has done it already
> or there is
> some other method to solve the problems.
>
> Bye
> 	Marcin
>
>
>
>

Greetings, deacon Marcus




RE: Problem with page encoding for ISO-8859-2

Posted by Martin van den Bemt <ma...@isallineed.org>.
Do some tests with utf8.. The way java stores it's strings is with utf-16..
Maby that's your problem?

Mvgr,
Martin

> -----Original Message-----
> From: Marcin Jaskuła [mailto:jaskula@expro.pl]
> Sent: Monday, August 20, 2001 9:00 PM
> To: tomcat-user@jakarta.apache.org
> Subject: RE: Problem with page encoding for ISO-8859-2
>
>
> Hi
>
> Yes, the data in the dB are stored as Latin2 so it should be the same like
> for ISO-8859-2.
> There was no this problem with JServ so the problem is in
> encoding the data
> by Tomcat (I think).
>
> Moreover, Tomcat writes new data to the dB changing characters to the
> Unicode:
> ł -> &#322;   (6 characters!!!)
> so I cannot sort the data now in the SQL!
>
> Marcin
>
> >-----Original Message-----
> >From: Martin van den Bemt [mailto:martin@isallineed.org]
> >Sent: Monday, August 20, 2001 8:42 PM
> >To: tomcat-user@jakarta.apache.org
> >Subject: RE: Problem with page encoding for ISO-8859-2
> >
> >
> >
> >- Is the data in the db stored as ISO-8859-2 ? (looks like it is
> stored is
> >8859-1)
> >- Use UTF-8 to store the data, this way you can use UTF-8 as well
> >as the ISO
> >content type that corresponds with the data.
> >
> >If you gonna use utf 8 and run into a lot of MalformedInputExceptions you
> >can be sure that the data is stored as 8859-1..
> >
> >Mvgr,
> >Martin
> >
>
>


RE: Problem with page encoding for ISO-8859-2

Posted by Marcin Jaskuła <ja...@expro.pl>.
Hi

Yes, the data in the dB are stored as Latin2 so it should be the same like
for ISO-8859-2.
There was no this problem with JServ so the problem is in encoding the data
by Tomcat (I think).

Moreover, Tomcat writes new data to the dB changing characters to the
Unicode:
ł -> &#322;   (6 characters!!!)
so I cannot sort the data now in the SQL!

Marcin

>-----Original Message-----
>From: Martin van den Bemt [mailto:martin@isallineed.org]
>Sent: Monday, August 20, 2001 8:42 PM
>To: tomcat-user@jakarta.apache.org
>Subject: RE: Problem with page encoding for ISO-8859-2
>
>
>
>- Is the data in the db stored as ISO-8859-2 ? (looks like it is stored is
>8859-1)
>- Use UTF-8 to store the data, this way you can use UTF-8 as well
>as the ISO
>content type that corresponds with the data.
>
>If you gonna use utf 8 and run into a lot of MalformedInputExceptions you
>can be sure that the data is stored as 8859-1..
>
>Mvgr,
>Martin
>


RE: Problem with page encoding for ISO-8859-2

Posted by Martin van den Bemt <ma...@isallineed.org>.
- Is the data in the db stored as ISO-8859-2 ? (looks like it is stored is
8859-1)
- Use UTF-8 to store the data, this way you can use UTF-8 as well as the ISO
content type that corresponds with the data.

If you gonna use utf 8 and run into a lot of MalformedInputExceptions you
can be sure that the data is stored as 8859-1..

Mvgr,
Martin

> -----Original Message-----
> From: Marcin Jaskuła [mailto:jaskula@expro.pl]
> Sent: Monday, August 20, 2001 8:39 PM
> To: Tomcat-User
> Subject: Problem with page encoding for ISO-8859-2
>
>
> Hi,
>
> I have change my JSP server form JServ to Tomcat (v. 3.2.3-1) recently and
> found several problems with page encoding.
> I have looked into the archive and found a lot of mails about the problem
> but no simple solutions.
>
> The problems are:
>
> 1. Compilation problem:
> I wrote some simple jsp page, which consists of some polish character:
>
> <%@ page contentType="text/html; charset=iso-8859-2" %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
> <html>
> <head>
> <meta http-equiv="content-type" content="text/html; charset=iso-8859-2">
> </head>
> <body>
> ą
> </body>
> </html>
>
> The server crashes with error 500:
>
> Internal Servlet Error:
>
> org.apache.jasper.JasperException: Unable to compile class for JSP
> Found 1 semantic error compiling "_0002fa_0002ejspa_jsp_0.java":
>
>     56.                 out.write("\n\n\n\n\n\n\n\u00-$\u00)%
> <----------\n\n\n");
>
> *** Error: The value of this "String" literal is invalid. Perhaps it
> contains a bad escape sequence?
>
> If I change "ą" to "a" it works !
> In my opinion the characters are translated to the Unicode in wrong way.
>
> 2. I cannot get proper values from the forms. When I use
> request.getParameter() method I get different characters then I write into
> form's fields (returned characters depend on the "page contentType" value
> but always are wrong).
>
> 3. When I try to print some data from a database I get wrong characters in
> the output !
>
>
> The best solution is to turn off all encoding of IO streams and before
> compilation of the jsp page. Maybe somebody has done it already
> or there is
> some other method to solve the problems.
>
> Bye
> 	Marcin
>
>
>