Professional Documents
Culture Documents
Requirements
- Java provides javax.servlet and javax.servlet.http APIs from Servlets
- These APIs are provided in servlet.jar file
- A program to be called as Servlet must be inherited from GenericServlet or HttpServlet
class
- GenericServlet provide three main methods
o init()
public void init()
o service()
public void service(ServletRequest req, ServletResponse res) throws
ServletException, IOException
o destroy()
public void destroy()
- HttpServlet provides some specific methods for operations
public void init()
public void service(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
public void doGet(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
public void doPost(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
public void destroy()
Receiving Data into servlets
- Use getParameter() method of HttpServletRequest object to read the data
- If data is coming from Get methods (QueryString) use doGet() or service()
- If data is coming from Post method use doPost() of service() method
- If you want that data should be accepted irrespective of method, override one method and
call it into another method