Contact Us
JSP Tutorial
Book Must Read

JSP implicit objects

Print   Email

Implicit objects are provided by JSP itself, we don’t need to define it we can simply use these objects by setting values and attributes. JSP container does all work like instantiating, defining and maintenance.

JSP provide following implicit objects

1. out

   out is  javax.servlet.jsp.JspWriter class use for printing. Out is Output Stream use response.getWriter()  to send output to client


  out.write("This is use for print output stream on client");

2. page

   page is used by java.lang.Object class. Page is instance of  JSP page’s Servlet.

    Object page = this; 

3. pageContext

    pageContext instance that contains all data’s information, which is associated with JSP   page. This helps to access attribute and other field’s object set in JSP page. pageContext is in javax.servlet.jsp.PageContext class. pageContext is to managed various scope of attribute in shared information object.
Method of pageContext are following:

Method Return Description
pageContext.findAttribute(String Name) Object Search for named attribute in JSP page Request,session, application scope  
pageContext.forward(String relativeURLPath) void This method is used to redirect or forward the current ServletRequest or ServletResponse to another active component
pageContext.getAttribute(String Name) Object Returns the object associated with name in the page scope
pageContext.getAttributesScope(String Name) int Get the scope where a given attribute is defined
pageContext.getErrorData() ErrorData Provide access to error information
pageContext.getException() Exception

Get current value of the exception Object

pageContext.getOut() JspWriter

Get current value of out object

pageContext.getRequest() ServletRequest

Get current value of request object

pageContext.getResponse() ServletResponse Get current value of response object
pageContext.getServletConfig() ServletConfig

Get any initialization parameters and startup configuration for this servlet

pageContext.getServletContext() ServletContext Gets the context from the servlet's ServletConfig object
pageContext.getSession() HttpSession Return the current value of session object

4. request

    The HttpServletRequest object that javax.servlet.http.HttpServletRequest interface is provided to access request objects in JSP. The HTTP request is send to server through request object.
 More example request object reference

5. response

The HttpServletResponse object that javax.servlet.http.HttpServletResponse interface is provided to send response object in JSP. The HTTP response is send to client through response object   
More example response object reference

6. session

    Session object is used to track information about a user, session is interface and maintain by HttpSession javax.servlet.http.HttpSession.
More example of session object reference

7. config

    config object is related to get servlet’s configuration information. It is in javax.servlet.ServletConfig interface. Servlet configuration object is used to pass information of servlet to Servlet container during initialization of servlet. This is defined in web.xml file with <init-param> and method is used to get getServletConfig()


Method use to get init param is getInitParameter() to get value inside <param-value> and getInitParameterNames() to get name of <param-name>

8. application

    Application object is used to share information for all JSPs and Servlets in the application context. Application is in javax.servlet.ServletContext.
More example of application object reference

9. exception

 Exceptions are condition that can be caught and recovered from it. If exception is not caught it should throw on error page. Exception when throw on error page it should be isErrorPage= true at in directive page.

<%@ page errorPage="error.jsp" %>

<%@ page isErrorPage="true" %>

Example of Exception Implicit object in JSP


<%@ page  language="java" errorPage="error.jsp" %>
<title>Implicit Exception object</title>

 String a=null;
 int b=Integer.parseInt(a);


<%@ page  language="java" import="*" isErrorPage="true"  %>
<title>Implicit Exception Error page</title>

The Exception is <strong><%= exception.toString() %></strong><br>
Message : <strong><%=exception.getMessage()%></strong><br>





If You Like this Article, share this

  View Forum Post  
Optimization of SQL queries for better performance
Example of Between in mysql
Example of sorting in mysql table
Example of join in mysql
Example of subquery in mysql
union join in mysql with example
error too many connection in mysql
calculate second highest salary
How to use select queries with array in mysql
Radio button pre selected in struts
Exception in thread "main" java.lang.NoClassDefFoundError
tree view in jsp
SSL implement in tomcat and java certificate
WARNING: Internal error flushing the buffer in release()
DynaForm validation problem in struts not working
Accessing JavaBean in servlet or servlet in javaBean.
  Privacy Policy