JSP Implicit Objects - request and response

Last Updated : 15 May, 2026

Implicit objects are pre-defined Java objects created by the JSP container and made available to every JSP page automatically. These objects can be used directly without declaration, simplifying development.

  • Both are implicit objects (no need to declare)
  • Created automatically by JSP container
  • Used for client-server communication

implicit objects

  1. request: instance of HttpServletRequest
  2. response: instance of HttpServletResponse
  3. config: instance of ServletConfig
  4. application: instance of ServletContext
  5. session: instance of HttpSession
  6. page context: instance of PageContext
  7. page: reference to the current JSP page object
  8. exception: instance of Throwable (used in error pages)
  9. out: instance of JspWriter

request Object

The request implicit object is an instance of HttpServletRequest. It is created by the web container for each client request and is used to:

  • Read form data
  • Access request parameters
  • Retrieve request headers
  • Obtain session information

request Object in Servlet

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession();
}

Note : In JSP, this object is implicitly available, so no declaration is required.

Implementation of JSP request Object to Read Form Data

Step 1: Create a Dynamic Web Project

  • Open Eclipse
  • Go to File -> New -> Dynamic Web Project
  • Project name: geeks2
  • Click Next -> Finish

This creates the basic JSP web application structure.

Step 2: Configure Apache Tomcat Server

  • Right-click project -> Properties
  • Select Targeted Runtimes
  • Choose Apache Tomcat
  • Apply and close

Step 3: Create the Form Page (index.jsp / HTML)

  • Create index.jsp inside WebContent / webapp folder.
  • This page collects user input and sends it as a request to Geeks.jsp.
HTML
<!DOCTYPE html>
<html>
<head>
    <title>Request Example</title>
</head>
<body>
<form action="Geeks.jsp">
    <input type="text" name="username">
    <input type="submit" value="submit">
</form>
</body>
</html>

Step 4: Create Geeks.jsp in the same folder.

HTML
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<!DOCTYPE html>
<html>
<body>
<%
    String name = request.getParameter("username");
    out.print("Welcome " + name);
%>
</body>
</html>

This JSP retrieves form data using the request implicit object and displays it.

Step 5: Deploy the Project on Server

  • Right-click project -> Run As -> Run on Server
  • Start Tomcat

Step 6: Open the Form Page in Browser

Access the application using:

http://localhost:8080/geeks2/

Step 7: Enter Input and Submit

Type Geeks in the text field and click Submit. The form sends the entered value to Geeks.jsp as a request parameter.

Image Reference

Step 8: Observe URL and Output

The data is passed using the GET method and read using request.getParameter().

Browser 9: http://localhost:8080/geeks2/Geeks.jsp?username=Geeks

Step 9: View Final Output.

The JSP sends the processed response back to the client.


 Output :

response Object

The response implicit object is an instance of HttpServletResponse. It is used to:

  • Send output to the client
  • Set HTTP headers
  • Add cookies
  • Redirect requests

Like request, the response object is implicitly created by the container.

Implementation of Using JSP response.sendRedirect()

Step 1: Create a Dynamic Web Project

  • Open Eclipse
  • Go to File -> New -> Dynamic Web Project

Step 2: Configure Apache Tomcat

  • Right-click project -> Properties
  • Select Targeted Runtimes
  • Choose Apache Tomcat

Step 3: Create redirect.jsp

Create a JSP file inside the WebContent folder.

html
<%@ page language="java" contentType="text/html; charset=UTF-8" %>
<!DOCTYPE html>
<html>
<body>
<%
    response.sendRedirect("https://www.geeksforgeeks.org/");
%>
</body>
</html>

This JSP uses the response implicit object to redirect the client.

Step 4: Deploy the Project on Server

Run the project on Tomcat.

Step 5: Access redirect.jsp in Browser

Open the URL:

http://localhost:8080/geeks2/redirect.jsp

Step 6: Redirection Occurs

  • The browser automatically navigates to GeeksforGeeks website.
  • sendRedirect() sends a new request to the specified URL.

Step 7: Observe URL Change

The browser URL changes to:

https://www.geeksforgeeks.org/

This confirms client-side redirection using the response object.

Output 
 

Advantage of JSP over servlet

  • JSP is easier to write and maintain compared to servlets
  • Separation of presentation (HTML) and logic (Java)
  • Implicit objects reduce boilerplate code
  • Faster development for UI-centric applications
Comment