Communicator e3000 MPE/iX Release 6.5 Express 2 (Software Release C.65.02) (30216-90322)

42 Chapter3
Technical Articles
Java Servlets for MPE/iX
Using Java Servlets
Writing Java Servlets
Java servlets on MPE follow the same rules and conventions as Java programs on MPE.
Any HP e3000 editor can be used to create a servlet file but, like Java programs, Java
servlets must be in bytestream format. Servlets created with vi or using Samba from a PC
will always be in bytestream format. Servlet files created using traditional HP e3000
editors such as EDIT/3000 and HP EDIT must be converted to bytestream using the tobyte
utility. For information on tobyte, execute "man tobyte" in the POSIX shell to invoke the
POSIX help facility.
The naming conventions for Java servlets follow those of Java programs:
The name should be followed by the extension .java.
The name is case-sensitive. While not a requirement, it is conventional to use mixed
case names with an initial capital and with additional capitals used if the class name
contains more than one word (for example, HelloWorld.java).
Java Servlet Class Definitions and Documentation
The jsdk.jar servlet classes in the JSDK2.0 are required for proper servlet execution
whether you write your own servlets or get them from another source. The jsdk.jar file
contains the javax.servlet and javax.servlet.http packages. To view the list of classes in
the jsdk.jar file, use the Java Archive Utility:
shell/iX>/usr/local/java/latest/bin/jar tvf /APACHE/SECURE/lib/jsdk.jar
or
shell/iX> /usr/local/java/latest/bin/jar tvf /APACHE/PUB/lib/jsdk.jar
For servlet API documentation and examples, use the following URL on your own server:
http://yourhost.com/JSDK2.0/doc/apidoc.
An Example Servlet
Servlets can be written to call any of the Java APIs available to Java applications.
Servlets use the Java standard extension classes in the packages javax.servlet (the basic
Servlet framework) and javax.servlet.http (extensions of the servlet framework for servlets
that answer HTTP requests) that are in the jsdk.jar file. Since servlets are written in Java
and follow a standard framework, they are portable between operating systems.
Here is an example of a simple servlet.
File: HelloWorld.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/**
* This is a simple example of an HTTP Servlet. It responds to the GET