Interview :: Servlets
Only one object at the time of first request by servlet or web container.
| Method | Description |
|---|---|
| public void init(ServletConfig config) | It is invoked only once when first request comes for the servlet. It is used to initialize the servlet. |
| public void service(ServletRequest request,ServletResponse)throws ServletException,IOException | It is invoked at each request.The service() method is used to service the request. |
| public void destroy() | It is invoked only once when servlet is unloaded. |
The web container or servlet container.
At the time of first request.
| Get | Post |
|---|---|
| 1) Limited amount of data can be sent because data is sent in header. | Large amount of data can be sent because data is sent in body. |
| 2) Not Secured because data is exposed in URL bar. | Secured because data is not exposed in URL bar. |
| 3) Can be bookmarked | Cannot be bookmarked |
| 4) Idempotent | Non-Idempotent |
| 5) It is more efficient and used than Post | It is less efficient and used |
PrintWriter is a character-stream class where as ServletOutputStream is a byte-stream class. The PrintWriter class can be used to write only character-based information whereas ServletOutputStream class can be used to write primitive values as well as character-based information.
The GenericServlet is protocol independent whereas HttpServlet is HTTP protocol specific. HttpServlet provides additional functionalities such as state management etc.
