This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Mozilla XML > May 2005 > XForms sending UTF-8?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author XForms sending UTF-8?
Daniel Thommes

2005-05-12, 7:43 pm

Hi,

I'm trying to get Mozilla XForms working together with a Java-Servlet. I
want the form to send utf-8 encoded data because auf the german
special-chars.
At this point X-Smiles and Formsplayer for IE work (after all) without
problems sending utf-8. But when I use special chars in Firefox, there
are strange letters reaching the Server.

Is there still no possibility to use utf-8? Or what am I doing wrong?

Greetings

Daniel

here the XForm (simple guestbook):

<?xml version="1.0" encoding="UTF-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:ev="http://www.w3.org/2001/xml-events">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<link rel="stylesheet" type="text/css" href="../css/guestbook.css" />
<xforms:model schema="../schemas/guestbook.xsd">
<xforms:instance xmlns="">
<guestbook>
<guest>
<name/>
<url/>
<email/>
<date>2005-05-01T13:37:00</date>
<message/>
</guest>
</guestbook>
</xforms:instance>
<xforms:submission id="send" action="../guestservlet" method="post"
encoding="UTF-8"/>
</xforms:model>
</head>
<body>
<h1>XML-Guestbook</h1>
<p>
<xforms:input ref="/guestbook/guest/name">
<xforms:label>Name</xforms:label>
</xforms:input>
</p>
<p>
<xforms:input ref="/guestbook/guest/url">
<xforms:label>URL</xforms:label>
</xforms:input>
</p>
<p>
<xforms:input ref="/guestbook/guest/email">
<xforms:label>e-mail</xforms:label>
</xforms:input>
</p>
<p>
<xforms:input ref="/guestbook/guest/message">
<xforms:label>message</xforms:label>
</xforms:input>
</p>
<p>
<xforms:submit submission="send">
<xforms:label>send</xforms:label>
</xforms:submit>
</p>
</body>
</html>
Allan Beaufour

2005-05-13, 7:28 am

Hi Daniel

On Friday 13 May 2005 00:05, Daniel Thommes wrote:
> I'm trying to get Mozilla XForms working together with a Java-Servlet. I
> want the form to send utf-8 encoded data because auf the german
> special-chars.
> At this point X-Smiles and Formsplayer for IE work (after all) without
> problems sending utf-8. But when I use special chars in Firefox, there
> are strange letters reaching the Server.
>
> Is there still no possibility to use utf-8? Or what am I doing wrong?


We should support utf-8. I've just tested it myself, and "Jürgen" in my
instance data seems to survive correctly both a submission using "utf-8" and
one using "iso-8859-1":
http://lab.cph.novell.com/~abeaufou.../encoding.xhtml

I'm not the submission wizard, but the handling and code looks fine at first
sight

--
Allan Beaufour
Novell Denmark

Novell, Inc., the leading provider of Net Business Solutions.

www.novell.com

Anne van Kesteren

2005-05-13, 7:33 pm

Daniel Thommes wrote:
> Is there still no possibility to use utf-8? Or what am I doing wrong?


Are you perhaps sending a charset parameter along with the wrong value?

Something like:

content-type:application/xml;charset=iso-8859-1

.... that would explain it as the charset parameter must be considered
authorative, even when there are declarations inside the document.


--
Anne van Kesteren
<http://annevankesteren.nl/>
Daniel Thommes

2005-05-13, 7:33 pm

All right! Thank you for that!

Knowing that Firefox should be able to do UTF-8 I solved the problem
recognizing that X-Smiles is the evil in this game. Obviously it is only
able to send ISO-8859-1 encoded data in spite of many hints in my Form.

So I had to do a little if-else in the servlet to save Jürgen's life :-)
The tips from my side:

Working with XForms, UTF-8 and Servlets requires a lot hints.

1)For sure a declaration like: <?xml version="1.0" encoding="UTF-8"?>

2)The submission element should contain an encoding hint:
<xforms:submission id="send" action="../readinput" method="post"
encoding="UTF-8"/>

3)Using xhtml there should be a meta-tag: <meta
http-equiv="content-type" content="text/html; charset=UTF-8"/>

4)Then you should take a look at my simple servlet:
setting Character Encoding for response AND request! Doing it a special
way for X-Smiles (for now).

public class ReadInput extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse
response)
throws ServletException, IOException {

StringBuffer xmlcontent = new StringBuffer("");
String helper, agent;
agent = request.getHeader("User-Agent");

if (agent.indexOf("X-Smiles") != -1) {
request.setCharacterEncoding("ISO-8859-1");
}
else {
request.setCharacterEncoding("UTF-8");
}

BufferedReader reader = request.getReader();

while ((helper = reader.readLine()) != null) {
xmlcontent.append(helper);
xmlcontent.append("\n");
}

response.setContentType("application/xml");
response.setCharacterEncoding("UTF-8");
PrintWriter out = response.getWriter();
out.print(xmlcontent);
}
}



Allan Beaufour wrote:
> Hi Daniel
>
> On Friday 13 May 2005 00:05, Daniel Thommes wrote:
>
>
>
> We should support utf-8. I've just tested it myself, and "Jürgen" in my
> instance data seems to survive correctly both a submission using "utf-8" and
> one using "iso-8859-1":
> http://lab.cph.novell.com/~abeaufou.../encoding.xhtml
>
> I'm not the submission wizard, but the handling and code looks fine at first
> sight
>

Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews