GenericServlet class
GenericServlet is a predefine class that exist in javax.servlet package.
GenericServlet class is an abstract class.
GenericServlet class implements Servlet interface to provide abstraction.
GenericServlet class provide all the implementation of servlet methods except of service method.
GenericServlet class also implements ServletConfig and Serializable interface.
Hello World Example using GenericServlet
package com.deepsingh44.blogspot.controller; import java.io.IOException; import javax.servlet.GenericServlet; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; public class HelloWorldGenericServlet extends GenericServlet { @Override public void service(ServletRequest arg0, ServletResponse arg1) throws ServletException, IOException { arg1.setContentType("text/html"); log("welcome to here"); arg1.getWriter().print("<h1>Hello Generic Servlet Example</h1>"); } }
Mapping GenericServlet in to web.xml file to create url for accessing from the browser.
<web-app> <servlet> <servlet-name>firstdemo</servlet-name> <servlet-class>com.deepsingh44.blogspot.controller.HelloWorldGenericServlet </servlet-class> </servlet> <servlet-mapping> <servlet-name>firstdemo</servlet-name> <url-pattern>/helloservlet</url-pattern> </servlet-mapping> </web-app>
No comments:
Post a Comment