JSP implicit objects are the objects that are available in every JSP.
Every JSP you write will be translated into a servlet class by the web container.
Every translated servlet will have the _jspService() method, which contains mainly nine local variables to hold Web Container objects.
public void _jspService(HttpServletRequest request, HttpServletResponse
response) throws java.io.IOException, ServletException {
PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
Throwable exception = null;
}
You cannot define these objects on your own in a JSP page.
Servlet | JSP |
---|---|
You can define custom package for servlet. | Translated servlet will be placed in org.apache.jsp package. |
You have to import the package required. | Translated servlet will have default Packages and custom Packages. |
You have to write servlet class by extending HttpServlet or GenericServlet. | Container writes or generates the Servlet class by extending HttpJspBase. |
You have to configure the servlet in web.xml or Annotations. | No configuration is required for JSP. |
Servlet lifecycle methods are public void init(ServletConfig) public void service(Request req, HSRes res) public void destroy() | JSP lifecycle methods are public void jsplnit() / _jsplnit() public void _jspservice(HSRequest req,HSRes res) public void jspdestroy()/jspDestroy() |
Servlet is initialized at container start-up or at first request. | JSP is initialized at container start-up or at first request. |
You have to compile the Servlet class written by you. | Container compiles the Translated Servlet Class. |
When you modify the Servlet then you have to re-compile, re-deploy and re-start the server. | When you modify the JSP, Container will do the automatic re-traslation, reompilation etc. |
Note : You can use the following to define comments in JSP page
<!-- THIS IS HTML COMMENT -->
<%-- THIS IS JSP Comment / Hidden COMMENT --%>