JSP implicit object is the Java object that the JSP container provides for each page

Source: Internet
Author: User

Jspan Implicit object

JSP implicit objects are the Java objects that the JSP container provides for each page, and developers can use them directly without explicitly declaring them. The JSP implicit object is also known as a pre-defined variable.

The nine implicit objects supported by JSPs:

Object Description
Request Instances of the HttpServletRequest class
Response Instances of the HttpServletResponse class
Out An instance of the PrintWriter class for outputting the results to a Web page
Session Instances of the HttpSession class
Application An instance of the ServletContext class, related to the application context
Config Instances of the ServletConfig class
PageContext An instance of the PageContext class that provides access to all objects in the JSP page and to namespaces
Page Similar to the This keyword in Java classes
Exception An object of the Exception class that represents the corresponding exception object in the JSP page where the error occurred
Request Object

The request object is an instance of the Javax.servlet.http.HttpServletRequest class. Each time a client requests a JSP page, the JSP engine creates a new request object to represent the requests.

The Request object provides a series of methods to get the HTTP header information, the Cookies,http method, and so on.

Response Object

The response object is an instance of the Javax.servlet.http.HttpServletResponse class. When the server creates the request object, it also creates a response object that responds to the client.

The response object also defines the interface that handles the HTTP header module. With this object, developers can add new cookies, timestamps, HTTP status codes, and so on.

Out Object

An Out object is an instance of the Javax.servlet.jsp.JspWriter class that is used to write content to the response object.

The original JspWriter class objects perform different instantiation operations based on whether the page has a cache. You can use the buffered= ' false ' property in the page directive to close the cache easily.

The JspWriter class contains the methods in most of the Java.io.PrintWriter classes. However, JspWriter has added some methods designed to handle caching. Also, the JspWriter class throws ioexceptions exceptions, and PrintWriter does not.

The following table lists the important methods that we will use to output the type of data such as Boolean,char,int,double,srtring,object:

Method Description
Out.print (DataType DT) Output type of value
OUT.PRINTLN (DataType DT) Output the type of a value and wrap it.
Out.flush () Refresh the output stream
Session Object

The session object is an instance of the Javax.servlet.http.HttpSession class. Has the same behavior as the session object in Java Servlets.

Session objects are used to track sessions between individual client requests.

Application Object

The Application object wraps the object of the servlet's ServletContext class directly, and is an instance of the Javax.servlet.ServletContext class.

This object represents this JSP page throughout the entire life cycle of the JSP page. This object is created when the JSP page is initialized and is removed with the invocation of the Jspdestroy () method.

By adding attributes to application, these properties are accessible to all JSP files that make up your web app.

Config object

The Config object is an instance of the Javax.servlet.ServletConfig class that wraps the object of the servlet's ServletConfig class directly.

This object allows the developer to access the initialization parameters of the servlet or JSP engine, such as the file path.

The following is how the Config object is used, not very important, so it is not commonly used:

Config.getservletname ();

It returns the servlet name contained in the <servlet-name> element, noting that the,<servlet-name> element is defined in the Web-inf\web.xml file.

PageContext Object

The PageContext object is an instance of the Javax.servlet.jsp.PageContext class that represents the entire JSP page.

This object is primarily used to access page information while filtering out most of the implementation details.

This object stores a reference to the request object and the response object. Application objects, config objects, session objects, and out objects can be exported by accessing the properties of this object.

The PageContext object also contains instruction information passed to the JSP page, including cache information, ErrorPage URL, page scope, and so on.

The PageContext class defines some fields, including Page_scope,request_scope,session_scope, Application_scope. It also provides more than 40 methods, half of which inherit from the Javax.servlet.jsp.JspContext class.

One of the important methods is Removearribute (), which can accept one or two parameters. For example, Pagecontext.removearribute ("Attrname") removes the related properties from four scopes, but the following method removes only the related properties in a specific scope:

Pagecontext.removeattribute ("Attrname", Page_scope);
Page Object

This object is a reference to the page instance. It can be seen as a representation of the entire JSP page.

The Page object is a synonym for this object.

Exception Object

The exception object wraps the exception information that was thrown from the previous page. It is often used to generate an appropriate response to an error condition.

JSP implicit object is the Java object that the JSP container provides for each page

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.