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

Chapter 3 43
Technical Articles
Java Servlets for MPE/iX
* and HEAD methods of the HTTP protocol.
*/
public class HelloWorld extends HttpServlet
{
public void doGet (HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
PrintWriter out;
String title = "Hello World Servlet";
// set content type and other response header fields first
response.setContentType("text/html");
// then write the data of the response
out = response.getWriter();
out.println("<HTML><HEAD><TITLE>");
out.println(title);
out.println("</TITLE></HEAD><BODY bgcolor=\"#FFFFFF\">");
out.println("<H2><Hello, World!<br>");
out.println("</BODY></HTML>");
out.close();
}
}
The above is an example of an HTTP servlet since it extends the HttpServlet class. For
HTTP servlets, an HTTP method (i.e., GET) is generally handled by a corresponding Java
method (i.e. doGet). The method should return a response which contains a body and
header field(s) which describe the body. In this example, the doGet method in the
HttpServlet base class is overridden. The body is the HTML output and the header field is
the Content-Type "text/html." This is an example of a static servlet that returns the same
output every time it is called.
Compiling Java Servlets
The class path is where the JVM looks for class definitions. The jsdk.jar file, which
contains servlet class definitons, should be specified to the JVM by adding its path to the
CLASSPATH environment variable. CLASSPATH can be set at the command line or in a
profile file:
shell/iX>export CLASSPATH=/APACHE/PUB/lib/jsdk.jar:$CLASSPATH
or
shell/iX>export CLASSPATH=/APACHE/SECURE/lib/jsdk.jar:$CLASSPATH