I know in general XML is the best way to transfer data. Because in a Servlet what gets returned is text. However in some cases the extra code for reading the XML is unneccessary. For instance, I have a login screen, and I want to return the user ID and also a list of jobs this user has access to. Usually it won't be more than 5 jobs for a user. So returning XML might be overkill. I was thinking of a straight text with a comma seperator as what should be returned. as in, "727, 12345, 65345, 12124, 62166" where 727 is the user ID and the other 4 are job numbers. But if I recall the StringTokenizer is not a class in the J2ME jar file. What do you guys think? Thanks Mark
In your case, the easiest way to go is to use DataOutputStream.writeInt() on the server side to write the five integers to the HTTP stream. On the client side, you can retrieve them in order by calling DataInputStream.readInt() five times.
So then the first int would have to be how many numbers are coming back, since it is not always just 5 times. Thanks Michael Mark
Joined: Jan 22, 2003
Michael's right. Sometimes it's useful though to have a human-readable data format (e.g. makes testing easier in some cases). In that case, you can just use comma-separated data as you originally described. Although StringTokenizer isn't available, it's little extra work to use String's indexOf(',') and substring methods. You'd probably also take advantage of String's trim() method to get rid of extra whitespace.
Joined: Oct 12, 2002
I used a comma-separated txt-file for my j2me, when I read it in the midlet I read one character at a time, in that way I could check for a comma, if I found one, I knew the next "job" was up!