GenericServlet
Advertisements
GenericServlet
GenericServlet class Implements Servlet, ServletConfig and Serializable Interfaces. It provides the implementation of all the methods of these Interfaces except the service method. GenericServlet class can handle any type of request so it is protocol Independent. You may create a generic Servlet by inheriting the GenericServlet class and providing the Implementation of the service method.
This is a implemented abstract class for Servlet Interface, have the implementation for all methods of Servlet interface except service method.
Methods of GenericServlet
All methos of Servlet Interface are inherit in GenericServlet class because it Implements Servlet Interface. Following methods are used in GenericServlet.
Example of Servlet by inheriting the GenericServlet class
Example
import java.io.*; import javax.servlet.*; public class GenericServletDemo extends GenericServlet { public void service(ServletRequest req,ServletResponse resp) throws IOException,ServletException { res.setContentType("text/html"); PrintWriter out=resp.getWriter(); out.print("<html><body>"); out.print("<b>Example of GenericServlet</b>"); out.print("</body></html>"); } }
Google Advertisment