Java Reference
In-Depth Information
Listing 18-3. The URLBuilder Helper Class
public class URLBuilder {
private StringBuffer mBuffer;
private boolean mHasParameters;
public URLBuilder(String base) {
mBuffer = new StringBuffer(base);
mHasParameters = false;
}
public void addParameter(String name, String value) {
// Append a separator.
if (mHasParameters == false) {
mBuffer.append('?');
mHasParameters = true;
}
else
mBuffer.append('&');
// Now tack on the name and value pair. These should
// really be URL encoded (see java.net.URLEncoder in
// J2SE) but this class appends the name and value
// as is, for simplicity. Names or values with spaces
// or other special characters will not work correctly.
mBuffer.append(name);
mBuffer.append('=');
mBuffer.append(value);
}
public String toString() {
return mBuffer.toString();
}
}
You will need to set the MIDlet property PasswordMIDlet-URL to point to the location of the
running PasswordServlet .
A simple implementation of a protected password servlet is shown in Listing 18-4.
Listing 18-4. The PasswordServlet Class
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import java.util.*;
Search WWH ::




Custom Search