Java Reference
In-Depth Information
L ISTING 5.11 Continued
* check if this pair is a valid license
private boolean check(String id, String pwd) {
return (id.charAt(0)==pwd.charAt(0));
Let's comment on Listing 5.11 before getting into its deployment details.
The simple client-server communication protocol requires the client to issue a GET request
passing in two parameters: license-id and license-pwd . The server (that is, our
LicenseServlet ) checks to see if the pair (id, password) is valid, and returns the result back to
the client. The resulting Web page is used by the client MIDlet to be shown directly to the user
via the wireless device screen (lines 37-43 in Listing 5.11).
The result of the password-id validity check is appended as a header to the HTTP response
(namely, “ outcome ”with values “ true ”or“ false ”) at line 35. Also, here the unscramble
method relating the communication security (lines 55-57) has been kept merely idempotent for
simplicity. The check method returns true when the license id matches the password input by
the user (Lines 22-25) simply controlling if the first character is the same. A more realistic
implementation would require a key-validation function, accessing a database or some data
file, and so on.
Deploying the License Servlet
Normally during development, all the application-related files are left “loose” in the WEB-
INF/classes directory in the application's document root. This could be a legitimate deploy-
ment option, but often, it is preferred to pack all those items in one WAR file for easier
In Tomcat, for example, all Web applications are gathered in the directory Webapps in the
Tomcat home directory (from here on <TOMCAT_HOME> ). Note that with few changes the follow-
ing procedure is applicable to any other standard servlet containers.
We are assumed to have created the application directory (in our case, license ). Within it, the
directory WEB-INF contains the classes directory (for all the Java classes; in our case, just one)
and the Web.xml file shown in Listing 5.12. All other files (HTML, JSP, and so on) may be put
in the application directory. In our simple case, we don't have any static content file. Then,
one may zip the resulting directory tree—once completed and tested—into a WAR file to be
distributed to other servlet containers that will run our License Servlet.
Search WWH ::

Custom Search