Java.Servlet.What implicit, internal objects and methods are there in a JSP page?

📜 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:

ObjectTypePurpose
requestHttpServletRequestRepresents the client request (parameters, headers, etc.)
responseHttpServletResponseRepresents the server’s response to the client
sessionHttpSessionRepresents the user’s session
applicationServletContextRepresents the web application (global data)
outJspWriterWrites output to the response (HTML)
configServletConfigServlet configuration for this JSP page
pageContextPageContextProvides access to all scopes and other server-side objects
pageObject (current JSP page instance)This is the JSP page itself (like this in Java)
exceptionThrowableRepresents an exception (only available in error pages)

🔵 Brief Description of Each:

ObjectDescription
requestRead request parameters (request.getParameter("name")), request headers, etc.
responseSet response content type (response.setContentType("text/html")), send redirects
sessionSave and retrieve user-specific data across multiple requests
applicationStore global attributes accessible by all users (application.setAttribute("key", value))
outSend HTML/text output directly to the browser (out.print("Hello"))
configAccess initialization parameters specific to the JSP servlet
pageContextManage all scopes (page, request, session, application) + other helpers
pageRefers to the instance of the servlet generated from JSP
exceptionOnly 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 from web.xml.

🎯 Summary

TermMeaning
Implicit ObjectsBuilt-in variables ready for use without declaration.
Internal MethodsUseful 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:

CategoryNames
Request/Responserequest, response
Session/Applicationsession, application
Output/Writerout
Configurationconfig, pageContext
Page Referencepage
Error Handlingexception (only in error pages)
This entry was posted in Без рубрики. Bookmark the permalink.