You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Reto Badertscher <rb...@i-netsystems.com> on 2001/07/17 14:11:36 UTC

Template encoding

Hello,

what's the best way to encode values (e.g. family_name in a person object)
stored in the velocity context to display in HTML?
I just wrote a utility which translates characters into HTML numeric
entities (e.g.  ä -> &#228),
that means, that every value stored in the context should be translated
before storing it.
Later i checked the EventCartridge (the idea was to intercept writing the
HTML rendering) - is that the correct way do do it or exists simpler and
better way to accomplish this task.

Thanks in advance for any help.

Reto Badertscher


AW: Template encoding

Posted by Reto Badertscher <rb...@i-netsystems.com>.
Thanks for your help,

do you have a working example? For me it doesn't work to specify only
'<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">'
nor set 'template.put("CONTENT_TYPE","text/html; charset=iso-8859-1");' in
my servlet.
I have to translate my values to numeric entities and for the templates i'm
using Dreamweaver which translates international characters to HTML entities
(e.g. ä to &auml;) during editing.

BTW, what's the meaning of AFAIK

Reto

-----Ursprüngliche Nachricht-----
Von: Paulo Gaspar [mailto:paulo.gaspar@krankikom.de]
Gesendet: Dienstag, 17. Juli 2001 19:02
An: velocity-user@jakarta.apache.org
Betreff: RE: Template encoding


AFAIK, that is the simplest/most-general way to do it, if you want to
encode those characters as you exposed.

Most modern browsers will accept characters as the "ä" if you declare
an Latin-1 encoding (which means that you will not have to translate
them into HTML entities).

To help the browser find out you are using Latin-1 (ISO-8859-1), you
should place the "Content-Type" <META> tag at the <HEAD> section of
your HTML page/template like in:
<HTML>
<HEAD>
...
  <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
...
</HEAD>
<BODY>
...

and, if in a servlet, it also helps to set the content type of the
response (HttpServletResponse) object with the same value:
  response.setContentType("text/html; charset=iso-8859-1");


I hope this helps,
Paulo Gaspar

> -----Original Message-----
> From: Reto Badertscher [mailto:rb@i-netsystems.com]
> Sent: Tuesday, July 17, 2001 2:12 PM
> To: velocity-user@jakarta.apache.org
> Subject: Template encoding
>
>
> Hello,
>
> what's the best way to encode values (e.g. family_name in a person object)
> stored in the velocity context to display in HTML?
> I just wrote a utility which translates characters into HTML numeric
> entities (e.g.  ä -> &#228),
> that means, that every value stored in the context should be translated
> before storing it.
> Later i checked the EventCartridge (the idea was to intercept writing the
> HTML rendering) - is that the correct way do do it or exists simpler and
> better way to accomplish this task.
>
> Thanks in advance for any help.
>
> Reto Badertscher
>


RE: Template encoding

Posted by Paulo Gaspar <pa...@krankikom.de>.
AFAIK, that is the simplest/most-general way to do it, if you want to
encode those characters as you exposed.

Most modern browsers will accept characters as the "ä" if you declare
an Latin-1 encoding (which means that you will not have to translate
them into HTML entities).

To help the browser find out you are using Latin-1 (ISO-8859-1), you
should place the "Content-Type" <META> tag at the <HEAD> section of
your HTML page/template like in:
<HTML>
<HEAD>
...
  <META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
...
</HEAD>
<BODY>
...

and, if in a servlet, it also helps to set the content type of the
response (HttpServletResponse) object with the same value:
  response.setContentType("text/html; charset=iso-8859-1");


I hope this helps,
Paulo Gaspar

> -----Original Message-----
> From: Reto Badertscher [mailto:rb@i-netsystems.com]
> Sent: Tuesday, July 17, 2001 2:12 PM
> To: velocity-user@jakarta.apache.org
> Subject: Template encoding
>
>
> Hello,
>
> what's the best way to encode values (e.g. family_name in a person object)
> stored in the velocity context to display in HTML?
> I just wrote a utility which translates characters into HTML numeric
> entities (e.g.  ä -> &#228),
> that means, that every value stored in the context should be translated
> before storing it.
> Later i checked the EventCartridge (the idea was to intercept writing the
> HTML rendering) - is that the correct way do do it or exists simpler and
> better way to accomplish this task.
>
> Thanks in advance for any help.
>
> Reto Badertscher
>