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
|
eg Hello World Servlet:
|
import java.io.*;
|
import java.servlet.*;
|
public class HelloWorldServlet extends GenericServlet {
|
public void service(ServletRequest req, ServletResponseres)
|
throws ServletException, IOException{
|
PrintStream out = newPrintStream(res.getOutputStream());
|
out.println("Hello world!");}
|
public String getServletInfo() {
|
return "Hello World Servlet"; }
|
}
|