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 |
}
|