This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori 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.
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.