Difference between Servlet and JSP

Difference between Servlet and JSP:

To write the Servlet class we need to extends HttpServlet or GenericServlet
For JSP container generates the Servlet class by extending HttpJspBase
For Servlet we need to configure Servlet in web.xml or use annotation
No need to configure in web.xml file
Servlet life cycle methods:
1.    Public void init(ServletConfig)
2.    Public void service(HttpServletRequest res, HttsServletResponse)
3.    Public void destroy()
JSP life cycle methods:
1.    Public void jspInit() or _jspInit()
2.    Public void _jpsService(HttpServletRequest res, HttpServletResponse res)
3.    Public jpsDestroy() or _jspDestroy()
If we modify the Servlet class then need to compile or redeploy and restart the server
When we modify JSP container will do the automatic re-translation or re-compilation
For Servlet we can define any package
For JSP translated Servlet will be placed in org.apched.jsp package
Servlet is more faster for first request
JSP is slower than servlet for first request


Post a Comment