JSP Implicit Objects - page and exception

JSP page -

page implicit object represents an java.lang.Object. It is a reference to the servlet instance (generated from jsp during conversion of jsp into servlet by web controller). In other words we can say that, page represents the current page. We can also use this(object of current class) in place of page, both are doing the same thing, So page is rarely used.

Example -

In this simple example we will use page implicit object to get and display the name of currently executing jsp page.

1-index.jsp - Create a file named index.jsp and add the following code -

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
        <title>JSP Page</title>
        <h1>page implicit object demo</h1>
        String name = page.getClass().getName();  // this.getClass().getName();
        out.println("Page Name is - "+name);

2- If index.jsp is not your default page, then set it to default by adding the following code in web.xml file -
3- Now run the project and it will show you the jsp page name -

Download this example (NetBeans implementation) - Click Here

JSP exception -

exception is an object of java.lang.Throwable and is used for exception handling in jsp. exception object is only available in jsp Error pages.
We will discuss it in detail with Error Pages.