Basic HTML version of Foils prepared May 19 99

Foil 40 Programming Java Servlets

From Overview of JDBC: Java Database Connectivity Basic Information Track Computational Science Course CPS616 -- Spring Semester 1999. by Nancy McCracken,(Sangetta Aggarwal, Meryem Ispirli, Udayan Parvate, Tom Pulikal, Chao-Wei Ou)


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, ServletResponse res)
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 Mon Jul 5 1999