Basic HTML version of Foils prepared 4 Feb 98

Foil 38 Programming Java Servlets

From Overview of JDBC and its use with CORBA or Java RMI CPS616 Technologies of Information Age -- Spring 1998. by Nancy McCracken(Sangetta Aggarwal, Udayan Parvate, Tom Pulikal)


1 Servlets :
  • must import the java.servlet package
  • must extend the GenericServlet class or HttpServlet class if implementing http features
  • must override the service method in the class
2 eg Hello World Servlet:
3 import java.io.*;
4 import java.servlet.*;
5 public class HelloWorldServlet extends GenericServlet {
6 public void service(ServletRequest req, ServletResponseres)
7 throws ServletException, IOException{
8 PrintStream out = newPrintStream(res.getOutputStream());
9 out.println("Hello world!");}
10 public String getServletInfo() {
11 return "Hello World Servlet"; }
12 }

in Table To:


© Northeast Parallel Architectures Center, Syracuse University, npac@npac.syr.edu

If you have any comments about this server, send e-mail to webmaster@npac.syr.edu.

Page produced by wwwfoil on Sun Nov 29 1998