What are implicit objects and their uses in JSP

The JSP technology provides provide certain implicit objects which are based on Servlet API, these objects can be access using standard variables names. The implicit objects are automatically available to use in JSP page without writing any extra code.

The implicit objects are created by web server and make them available across the JSP page, available using standard variable, so these objects called as implicit objects.

The implicit objects are parsed by the container and inserted properly into the generated servlet code. The implicit objects are available only within the jspService () method but not in declaration.

Implicit objects can be used for different purposes. There are nine implicit objects. Here is the list of all the implicit objects Its type.

application is the instance of javax.servlet. ServletContext

config is the instance of javax.servlet.ServletConfig

page is the instance of java.lang.Object

pageContext is the instance of javax.servlet.jsp.PageContext

session is the instance of javax.servlet.http.HttpSession

request is the instance of javax.servlet.ServletRequest

response is the instance of javax.servlet.ServletResponse

out is the instance of javax.servlet.jsp.JspWriter

exception is the instance of java.lang.Throwable

The application implicit object

The application object represents the servlet context; it has been obtained from the servlet configuration object. It is type of javax.servlet.ServletContext and has application scope. The application object allows the share information between the JSP pages generated servlet and web component within same application context.

The config implicit object

The config object is the type of ServletConfig for the JSP page and it has page scope. It is a instance of type javax.servlet.ServletConfig. This object allows passing the initialization data to a JSP page’s servlet. Parameters of this object can be set in the deployment descriptor web.xml inside the element jsp-file. You can get the initialization parameters by using getInitParameter() method.

The page implicit object

The page object is an instance of the page’s implementation servlet class that is processing the current request. It is instance of type java.lang.Object, and it has page scope. The page object represents the current page that is used to call the methods defined by the generated servlet class.

The pageContext implicit object

The pageContext provides a single point of access to many of the page attribute and is convenient place to put shared data within the page. It is the instance of type javax.servlet.jsp.pageContext and has page scope.

The pageContext object has a page scope. The pageContext is the context for the JSP page itself that provides a single API to manage the various scoped attributes. This JSP API is widely used for implementing JSP custom tags.

The session implicit object

The session implicit object represents the session created for the requesting user. Session is created automatically, and a new session is available even when there is no incoming session.

Session object has a session scope that is an instance of javax.servlet.http.HttpSession class. It is the most commonly used object to manage the state contexts. This object persist information across multiple user session.

But if you have used a session=”false” attribute in the page directive; the session object variable will not be available.

The request implicit object

The request object has request scope, and is an instance of the javax.servlet.ServletRequest class. It encapsulates the request coming from the user and being processed by the JSP. It is passed to the JSP by the container as a parameter of the _jspService ( ) method. The request implicit object has a request scope that is used to access the HTTP request data, and also provides a context to associate the request-specific data. It uses the getParameter () method to access the request parameter.

The response implicit object

The response implicit object has page scope, and is an instance of javax.servlet.ServletResponse. It encapsulates the response generated by the JSP to be sent back to the user in response to the request. It is generated by the container and passed to the JSP as a parameter to the _jspService ( ) method.

The out implicit object

The out object is the object that allows us to write into the output stream to the client. To make the response object useful, this is a buffered version of the javax.servlet.jsp.JspWriter. The buffer size can be adjusted by the buffer attribute of the page directive. It provides the output stream that enable access to the servlet’s output stream.

The exception implicit object

The object has a page scope and is an instance of java.lang.Throwable class. This object allows the exception data to be accessed only by designated JSP error pages.