JSP operating principle and nine implicit object description

  • 2020-05-30 20:56:11
  • OfStack

On the first visit of each JSP page, the WEB container passes the request to the JSP engine (that is, an Java program) for processing. The JSP engine first translates JSP into 1 _jspServlet(essentially 1 servlet), and then calls it as servlet calls it.

Since the first access of JSP will be translated into servlet, the first access will usually be slow, but on the second access, if the JSP engine finds that JSP has not changed, it will no longer translate, but directly call it, so the execution efficiency of the program will not be affected.

When the JSP engine calls _jspServlet corresponding to JSP, it passes or creates nine web developing-related objects for _jspServlet to use. The designers of JSP technology specifically defined nine variables to make it easier for developers to obtain references to these web objects when writing JSP pages. These variables allow developers to quickly obtain references to these nine objects on JSP pages.

What are these 9 objects respectively, and the effect also is the knowledge that the written test often inspects.

Jsp9 large implicit object

request // represents the request object

response // represents the response object

config // represents servletConfig objects

application // represents servletContext objects




out // represents response.getWriter (), a character output stream object


pageContext object

The pageContext object is one of the most important objects in the JSP technology, and it represents the running environment of the JSP page.

This object not only encapsulates references to eight other implicit objects,

It itself is also a domain object that can be used to hold data.

In addition, this object encapsulates some common operations that are often involved in web development, such as introducing and jumping to other resources, retrieving properties in other domain objects, and so on.

Get other objects through pageContext

The getException method returns an exception implicit object

The getPage method returns an page implicit object

The getRequest method returns the request implicit object

The getResponse method returns an response implicit object

The getServletConfig method returns an config implicit object

The getServletContext method returns an application implicit object

The getSession method returns the session implicit object

The getOut method returns the out implicit object

pageContext encapsulates the meaning of the other 8 built-in objects. Consider: if you pass an pageContext object to a normal java object during programming, what will this java object do?

pageContext as a domain object

Method of the pageContext object

public void setAttribute(java.lang.String name,java.lang.Object value)

public java.lang.Object getAttribute(java.lang.String name)

public void removeAttribute(java.lang.String name)

The pageContext object also encapsulates methods to access other domains

public java.lang.Object getAttribute(java.lang.String name,int scope)

public void setAttribute(java.lang.String name, java.lang.Object value,int scope)

public void removeAttribute(java.lang.String name,int scope)

Constants representing the fields





Related articles: