JSP | Implicit Objects – request and response
Last Updated :
15 Feb, 2021
Perquisite: Introduction To JSP
JSP stands for Java Server Pages, and it’s a server side technology. It’s used for creating web applications and dynamic web content. The main property of JSP is that we can insert our java code inside our HTML page using JSP tag. JSP provides you platform-independent pages.
html
<%@ page language = "java" contentType = "text/html; charset = UTF-8"
pageEncoding = "UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01
< html >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8" >
< title >Insert title here</ title >
</ head >
< body >
<% Geeks saying hello to JSP %>
</ body >
</ html >
|
Implicit objects are a set of Java objects that the JSP Container makes available to developers on each page. These objects may be accessed as built-in variables via scripting elements and can also be accessed programmatically by JavaBeans and Servlets.JSP provide you Total 9 implicit objects which are as follows
- request: This is the object of HttpServletRequest class associated with the request.
- response: This is the object of HttpServletResponse class associated with the response to the client.
- config: This is the object of ServletConfig class associated with the page.
- application: This is the object of ServletContext class associated with the application context.
- session: This is the object of HttpSession class associated with the request.
- page context: This is the object of PageContext class that encapsulates the use of server-specific features. This object can be used to find, get or remove an attribute.
- page object: The manner we use the keyword this for current object, page object is used to refer to the current translated servlet class.
- exception: The exception object represents all errors and exceptions which is accessed by the respective jsp. The exception implicit object is of type java.lang.Throwable.
- out: This is the PrintWriter object where methods like print and println help for displaying the content to the client.
In this article, two of the main objects which are request and response are discussed
request Object
The JSP request is an implicit object which is provided by HttpServletRequest. In the servlet, we have to first import javax.servlet.http.HttpServletRequest then we have to create its object for taking input from any HTML form as.
Syntax :
import javax.servlet.http.HttpServletRequest;
public class LoginServlet extends HttpServlet
{
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
HttpSession session = request.getSession()
}
}
In JSP, the request object is implicitly defined so that you don’t have to create an object. JSP request object is created by the web container for each request of the client. It’s used for getting the parameter value, server name, server port, etc.
In the below example we are using a request object to display the username.
html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
< html >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8" >
< title >Insert title here</ title >
</ head >
< body >
< form action = "Geeks.jsp" >
< input type = "text" name = "username" >
< input type = "submit" value = "submit" >< br />
</ form >
</ body >
</ html >
|
Output

response object
This is the HttpServletResponse object associated with the response to the client. The response object also defines the interfaces that deal with creating new HTTP headers. Through this object the JSP programmer can add new cookies or date stamps, HTTP status codes, etc.
html
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
< html >
< head >
< meta http-equiv = "Content-Type" content = "text/html; charset=UTF-8" >
< title >Insert title here</ title >
</ head >
< body >
<%
String name=request.getParameter("username");
out.print("Welcome "+ name);
%>
</ body >
</ html >
|
Output

In JSP the response object is implicitly defined, so you don’t have to create an object. JSP response object is created by the web container for each request of the client. It basically is used for redirecting to any other resource.
In the below example we use the response object to send the user on Geeksforgeeks homepage.
html
<!DOCTYPE html>
< html >
< head >
< meta charset = "UTF-8" >
< title >GeeksforGeeks</ title >
</ head >
< body >
<%
//below line in JSP redirect you to geeksforgeeks page
response.sendRedirect("geeksforgeeks.org");
%>
</ body >
</ html >
|
Output

Advantage of JSP over servlet :
- Servlets are difficult to code than JSP. In another way, we can say, JSP is the replacement for Servlets.
- In Servlets, both static code and dynamic code are put together. In JSP, they are separated.
- The objects of PrintWriter, ServletConfig, ServletContext, HttpSession and RequestDispatcher etc. are created by the Programmer in Servlets. But in JSP, they are built-in and are known as implicit objects.
Disadvantage :
- JSP pages require more memory to hold the page.
- The output is in HTML which is not rich for viewers.
Similar Reads
JSP - Out Implicit Object
In Java, JSP stands for JavaServer Pages. It is a technology that can used for creating dynamic web pages in Java and the Out implicit object in JSP is used to send content to the web client for rendering. In this article, we will discuss the concept of Out implicit object in JSP. Out Implicit Objec
3 min read
JSP PageContext - Implicit Objects
PageContext extends JspContext to contribute helpful context details while JSP technology is applied in a Servlet environment. A PageContext is an instance that gives access to all the namespaces related to a JSP page, gives access to some page attributes and a layer over the application details. Im
4 min read
JSP Config - Implicit Objects
JSP Config is an implicit object which is used to transmit the configuration details to the JSP page. In JSP, Config is an instance of type ServletConfig. This implicit object is used to acquire an initialization parameter for a certain JSP page. For each JSP page, the config object is generated thr
2 min read
JSP Application - Implicit Objects
In JSP, application is an implicit object of type ServletContext. This is an instance of javax.servlet.ServletContext. It is generated onetime by the web container when web application or web project is deployed on server. This object is used to acquire the initialization parameter from the configur
3 min read
JSP - Exception implicit object
In Java, JSP is defined as JavaServer Pages. It is the technology that is used to create dynamic web pages in Java. The Exception implicit object in the JSP provides information about any exception that occurs during the execution of the JSP pages. Exception Implicit Object of JSPThe Exception impli
2 min read
Understanding Classes and Objects in Java
The term Object-Oriented explains the concept of organizing the software as a combination of different types of objects that incorporate both data and behavior. Hence, Object-oriented programming(OOPs) is a programming model, that simplifies software development and maintenance by providing some rul
10 min read
JSP - Client Request
In web development, a Client Request refers to a connection sent from a client to a server to edit data, and objects, or to perform or receive operations. In the case of JavaServer Pages (JSP), client requests can be processed using JSP files and servlets running on the web server. In this article,
4 min read
java.net.ResponseCache Class in Java
ResponseCache in java is used for constructing implementation of URLConnection caches, and it nominates which resource has to be cached and up to what time duration a resource needed to be cached. An instance of ResponseCache can be created using the system by doing : ResponseCache.setDefault(Respon
3 min read
Difference Between @RequestBody and @ResponseBody Annotation in Spring
To achieve the functionality of handling request data and response data in Spring MVC, @RequestBody and @ResponseBody annotations are used. So, in this article, we will go dive into the difference between @RequestBody and @ResponseBody annotations with an example. @RequestBody@RequestBody is mainly
3 min read
How to Make Post Request in Java Spring?
Java language is one of the most popular languages among all programming languages. There are several advantages of using the java programming language, whether for security purposes or building large distribution projects. One of the advantages of using JAVA is that Java tries to connect every conc
4 min read