Java Reference
In-Depth Information
Note In some applications, a server may return multiple cookie values. RFC 2965 has provisions for this.
In these cases, the cookie string parsing code can be considerably more complex than this example.
Listing 10-4 shows a class, CookieMIDlet , that uses this technique to maintain a session
with a server. It has a very bland user interface—just an empty Form with two commands. If you
invoke the Send command, the MIDlet sends an HTTP request and receives a response using
the cookie handling described earlier.
Listing 10-4. Saving a Server Session ID Cookie
import java.io.*;
import javax.microedition.io.*;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
public class CookieMIDlet
extends MIDlet
implements CommandListener, Runnable {
private Display mDisplay;
private Form mForm;
private String mSession;
public void startApp() {
mDisplay = Display.getDisplay(this);
if (mForm == null) {
mForm = new Form("CookieMIDlet");
mForm.addCommand(new Command("Exit", Command.EXIT, 0));
mForm.addCommand(new Command("Send", Command.SCREEN, 0));
mForm.setCommandListener(this);
}
mDisplay.setCurrent(mForm);
}
public void pauseApp() {}
public void destroyApp(boolean unconditional) {}
 
Search WWH ::




Custom Search