📜 Implicit Objects in JSP
Implicit Objects are automatically created by the JSP container and available to you inside a JSP page without any declaration.
You don’t need to create them — they just exist!
Here’s the list:
| Object | Type | Purpose |
|---|---|---|
request | HttpServletRequest | Represents the client request (parameters, headers, etc.) |
response | HttpServletResponse | Represents the server’s response to the client |
session | HttpSession | Represents the user’s session |
application | ServletContext | Represents the web application (global data) |
out | JspWriter | Writes output to the response (HTML) |
config | ServletConfig | Servlet configuration for this JSP page |
pageContext | PageContext | Provides access to all scopes and other server-side objects |
page | Object (current JSP page instance) | This is the JSP page itself (like this in Java) |
exception | Throwable | Represents an exception (only available in error pages) |
🔵 Brief Description of Each:
| Object | Description |
|---|---|
| request | Read request parameters (request.getParameter("name")), request headers, etc. |
| response | Set response content type (response.setContentType("text/html")), send redirects |
| session | Save and retrieve user-specific data across multiple requests |
| application | Store global attributes accessible by all users (application.setAttribute("key", value)) |
| out | Send HTML/text output directly to the browser (out.print("Hello")) |
| config | Access initialization parameters specific to the JSP servlet |
| pageContext | Manage all scopes (page, request, session, application) + other helpers |
| page | Refers to the instance of the servlet generated from JSP |
| exception | Only available on JSP error pages (isErrorPage="true") to handle exceptions |
📜 Internal/Important Methods in JSP (especially via pageContext)
Some very commonly used internal methods available through these implicit objects:
| Method (example) | Purpose |
|---|---|
request.getParameter("name") | Read form/input parameter |
response.sendRedirect("page.jsp") | Redirect the client |
session.setAttribute("user", userObj) | Store object in session scope |
application.getAttribute("config") | Read global object |
out.println("Hello World") | Write directly to browser output |
pageContext.getAttribute("attr") | Get an attribute from any scope |
pageContext.setAttribute("attr", value, PageContext.SESSION_SCOPE) | Set attribute in specific scope |
Also, some configuration methods:
config.getInitParameter("paramName")→ Read init parameters for the servlet.application.getInitParameter("appParamName")→ Read app-wide init parameters fromweb.xml.
🎯 Summary
| Term | Meaning |
|---|---|
| Implicit Objects | Built-in variables ready for use without declaration. |
| Internal Methods | Useful methods exposed by those objects (like getParameter(), setAttribute(), etc.). |
🔥 Example Using Multiple Implicit Objects
<%
String userName = request.getParameter("name");
session.setAttribute("currentUser", userName);
out.println("<h1>Hello, " + userName + "</h1>");
%>
- Read a request parameter.
- Store it in the session.
- Write output using
out.
📢 Special Note about exception:
- It only exists if you define a JSP page with:
<%@ page isErrorPage="true" %>
Otherwise, you won’t have access to exception.
🚀 Final Super Quick View:
| Category | Names |
|---|---|
| Request/Response | request, response |
| Session/Application | session, application |
| Output/Writer | out |
| Configuration | config, pageContext |
| Page Reference | page |
| Error Handling | exception (only in error pages) |