Java Servlet Sample Program
Servlets are the server side programming language.
Servlets are loaded by the container which instantiates the init() followed by the service() method. Destory() method is called to take the servlets out of service. init() and destroy() methods are called automatically and are called only once throughout the life cycle
Try out the sample simple servlet program
import javax.servlet.*;
import java.io.*;
public class HelloServlet extends HttpServlet
{
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType(”text/html”);
PrintWriter out = response.getWriter();
out.println(”<html><head><title>Hello!</title></head>”);
out.println(”<body bgcolor=\”white\”><h1>Hello Servlet World</h1>”);
out.println(”</body></html>”);
out.close();
}
}