Re: XForms sending UTF-8?

Daniel Thommes <[email protected]>
Newsgroups gmane.comp.mozilla.devel.xml
Organization Another Netscape Collabra Server User
Message-ID <[email protected]>
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:
> 
>>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/~abeaufour/xforms/encoding.xhtml
> 
> I'm not the submission wizard, but the handling and code looks fine at first 
> sight
>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.