This week's book giveaway is in the Agile and other Processes forum. We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line! See this thread for details.
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
David Price
Ranch Hand
Joined: Jan 22, 2003
Posts: 93
posted
0
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.
Niklas Junel
Greenhorn
Joined: Oct 12, 2002
Posts: 17
posted
0
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!
Thanks Niklas, but this thread is almost two years old, and two jobs ago.
Mark
Mateen Dar
Ranch Hand
Joined: Jan 14, 2005
Posts: 55
posted
0
i faced the same problem . their is no split function in j2me. so i just wrote my own function thata takes a string and a delimiter. about 5 lines of code. thats all.