Java-jsp an Implicit object

Source: Internet
Author: User
Tags ranges sessions

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 ExceptionObject allows the specified JSP to access the exception data.
1. Request Object

requestAn 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.

requestThe 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

responseAn 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.

responseObject 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

outAn 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‘ .

JspWriterObject contains java.io.PrintWriter most of the same methods as the class. However, there JspWriter are some additional ways to handle buffering. PrintWriterUnlike 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

sessionObject is javax.servlet.http.HttpSession an instance of the behavior that is identical to the behavior of the session object under the Java servlet.
sessionobject 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

applicationAn object is a Servlet direct wrapper of the generated ServletContext object, and is actually javax.servlet.ServletContext an instance of the object.

applicationAn 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

configAn 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

pageContextAn object is javax.servlet.jsp.PageContext an instance of an object. pageContextobject is used to represent the entire JSP page.

pageContextObjects 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.

pageContextThe object also contains information about the directives published to the JSP page, including buffering information, errorPageURL and page ranges.

PageContextThe 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

pageThe object is the actual reference to the page instance. You can think of it as an object representing the entire JSP page.

pageAn object is a this direct synonym for an object.

9. Exception Objects

exceptionThe 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.