JSP Implicit Object
In this chapter, we will discuss and learn about implicit objects in JSPs. These objects are Java objects that the JSP container provides to developers in each page, and developers can call them directly without explicitly declaring them. A JSP implicit object is also known as a pre-defined variable.
The following table lists the nine implicit objects supported by the JSP-
numbering |
Object |
Description |
1 |
request |
This is the object associated with the request HttpServletRequest . |
2 |
response |
This is the object associated with the client's response HttpServletResponse . |
3 |
out |
This is the object used to send the output to the client PrintWriter . |
4 |
session |
This is the object associated with the request HttpSession . |
5 |
application |
This is the object associated with the application context ServletContext . |
6 |
config |
This is the object associated with the page ServletConfig . |
7 |
pageContext |
This encapsulates the use of server-specific features, such as higher performance JspWriter . |
8 |
page |
This is just a synonym for invoking the method defined by the translated Servlet class. |
9 |
Exception |
Exception Object allows the specified JSP to access the exception data. |
1. Request Object
request
An object is javax.servlet.http.HttpServletRequest
an instance of an object. Whenever a client requests a page, the JSP engine creates a new object to represent the request.
request
The Cookie,http object provides a way to get HTTP header information, including form data, the method, and so on.
The request
complete set of methods associated with an object are covered in subsequent sections-jsp client requests.
2. Response Objects
response
An object is javax.servlet.http.HttpServletResponse
an instance of an object. Just as the server creates request
an object, it also creates an object to represent the response to the client.
response
Object also defines the interface that handles creating new HTTP headers. With this object, JSP programmers can add new cookies or date stamps, HTTP status codes, and so on.
The response
complete set of methods associated with an object is described in subsequent chapters-the JSP server response.
3. Out Object
out
An implicit object is javax.servlet.jsp.JspWriter
an instance of an object that is used to send content in a response.
Initializes an JspWriter
object to be instantiated differently depending on whether the page is cached. Buffering can be closed by using page
the properties of the directive buffered =‘false‘
.
JspWriter
Object contains java.io.PrintWriter
most of the same methods as the class. However, there JspWriter
are some additional ways to handle buffering. PrintWriter
Unlike an object, an JspWriter
exception is thrown IOExceptions
.
The following table lists the important methods for writing,,,, and boolean
char
int
double
object
String
Other types of data.
numbering |
Method |
Description |
1 |
out.print(dataType dt) |
Print data Type value |
2 |
out.println(dataType dt) |
Prints the data type value, and then terminates the line with a new line (newline) character. |
3 |
out.flush() |
Refresh Stream |
4. Session Object
session
Object is javax.servlet.http.HttpSession
an instance of the behavior that is identical to the behavior of the session object under the Java servlet.
session
object is used to track client sessions between client requests. The full use of the session object will be described in the subsequent chapters-JSP session trace.
5. Application Objects
application
An object is a Servlet
direct wrapper of the generated ServletContext
object, and is actually javax.servlet.ServletContext
an instance of the object.
application
An object is a representation of a JSP page throughout its life cycle. When the JSP page is initialized, the object is created and the object is deleted when the JSP page is deleted by the jspDestroy()
method application
.
by application
adding property values to an object, you can ensure that all of the JSP files that make up your Web application can access it.
The JSP user clicks on the statistics section to describe and learn application
how the object is used.
6. config Object
config
An object is an instantiation of a javax.servlet.ServletConfig
direct wrapper around the object that is generated by the servlet ServletConfig
.
This object allows the JSP programmer to access the servlet or JSP engine initialization parameters, such as path or file location.
The following configuration method is the only configuration method that can be used, and its usage is very simple-
config.getServletName();
Java
This returns the current servlet
name, which is the string that is contained in the WEB-INF\web.xml
element defined in the file <servlet-name>
.
7. PageContext Objects
pageContext
An object is javax.servlet.jsp.PageContext
an instance of an object. pageContext
object is used to represent the entire JSP page.
pageContext
Objects are intended as a means of accessing information about a page, while avoiding most of the implementation details.
This object stores a reference to the request and response object for each request. Applications, configurations, sessions, and output objects are exported by accessing the properties of this object.
pageContext
The object also contains information about the directives published to the JSP page, including buffering information, errorPageURL
and page ranges.
PageContext
The class defines several fields, including:,, PAGE_SCOPE
REQUEST_SCOPE
SESSION_SCOPE
and APPLICATION_SCOPE
, which identify four ranges. It also supports more than 40
one method, of which about half are javax.servlet.jsp.JspContext
inherited from the class.
One of the important ways is removeAttribute
. This method accepts one or two parameters. For example, pageContext.removeAttribute("attrName")
deleting a property from all scopes, and the following code only removes it from the page range-
pageContext.removeAttribute("attrName", PAGE_SCOPE);
Java
You can see how it is used in the JSP File Upload section pageContext
.
8. Page Object
page
The object is the actual reference to the page instance. You can think of it as an object representing the entire JSP page.
page
An object is a this
direct synonym for an object.
9. Exception Objects
exception
The object is a wrapper that contains the exception that was thrown on the previous page. It is typically used to generate an appropriate response to an error condition.
We'll cover the full usage of this object in the JSP exception handling chapter.
Java-jsp an Implicit object