PDA

View Full Version : What is the encoding sending from lzx


onoke
04-11-2005, 11:19 PM
I am trying to get multibyte data throw from lzx to jsp by the "<form>" on lps3.0b1.
If i use the html, the jsp is able to get some multibyte data correctly. But in case of using lzx, the same jsp is not able to get it.
They would be like "???" characters.
I guess it causes the encoding mismatch between the lzx and jsp.
Then let me know, what is the encoding the lzx throw to the jsp? Or could i change it?

The sample of the jsp as following.
<%@ page import="java.util.*,java.io.*" %>
<%
request.setCharacterEncoding("x-sjis");
String key1 = ( String )request.getParameter( "in1" );
FileOutputStream fo = new FileOutputStream( "aaa.txt");
BufferedWriter fw = new BufferedWriter( new OutputStreamWriter( fo, "x-sjis" ));
fw.write( key1, 0, key1.length() );
fw.close();
fo.close();
%>

The sample of the lzx as following.
<?xml version="1.0" encoding="x-sjis"?>
<canvas bgcolor="0xeaeaea" width="640">
<dataset name="echoer" src="http:echo.jsp"/>
<tabs id="tb" x="40" y="$once{tt.y + tt.height}">
<tabpane text="input form">
<form id="ex1">
<submit name="submitter" data="${echoer}"/>
<edittext name="in1"></edittext>
<button isdefault="true" onclick="parent.submitter.submit()">登録</button>
</form>
</tabpane>
</tabs>
</canvas>


And the sample of the html as following.
<html>
<head></head>
<body>
<form method="post" action="aaa.jsp">
<input type="text" name="in1">
<input type="submit" value="submit">
</form>
</body>
</html>


Any advice thanks.

hqm
04-12-2005, 06:49 AM
As of LPS 3.0b2, the Laszlo app will encode data as URL-encoded UTF-8.

So your JSP needs to URL-decode the data that is posted up to it (may be either GET or POST), and then treat that data as raw UTF-8 byte stream, and do the conversion accordingly.


Here is an example of a "echo" JSP which will
accept multi-byte data from the demo app in examples/components/form_example.lzx, and echo it back properly to the app:


<?xml version="1.0"?>
<!-- * X_LZ_COPYRIGHT_BEGIN ************************************************** *
* Copyright 2001-2004 Laszlo Systems, Inc. All Rights Reserved. *
* Use is subject to license terms. *
* X_LZ_COPYRIGHT_END ************************************************** **** -->



<%@ page import="java.util.*" %>
<%@ page contentType="text/xml; charset=UTF-8" %>

<response>
<%

////////////////

Enumeration params = request.getParameterNames();
while(params.hasMoreElements()) {
String n = (String)params.nextElement();
String[] v = request.getParameterValues(n);
for(int i = 0; i < v.length; i++) {
String str = v[i];
// parse query args (URLENCODING) to Unicode as UTF8
byte p[] = str.getBytes("8859_1");
String ustr = new String(p, 0, p.length, "UTF-8");

out.print("<formcomponent name='" + n + "'><![CDATA[");
out.print(ustr);
out.println("]]></formcomponent>");
}
} %>
</response>

onoke
04-12-2005, 05:09 PM
Thank you hqm.
I also confirmed it on lps3.0b1.

hqm
04-12-2005, 05:25 PM
I have observed in some situations that it is difficult to get the Tomcat servlet API to let me get my hands on the data before it has made some incorrect character set encoding decision. This has been a problem for me more with the new serverless mode of operation in LPS 3.0, where the Flash client does not add proper charset info in the HTTP headers it sends. I have found various work arounds which sometimes require me to get the raw byte stream in my Java servlet, and bypass the getParameter() methods in the servlet API.