JSP built-in objects respectively function and important methods

  JSP provides some internal objects to simplify the development of pages. These internal objects do not need to be instantiated by the JSP writer, they are implemented and managed by the container (Tomcat context) and can be used in all JSP pages. All internal objects are only useful for scripts or expressions, but not in JSP declarations. JSP has the following internal objects:

request

  This object is the request object , each request object encapsulates this user request, and all request parameters are encapsulated in the request object. Therefore, it is an important way to obtain request parameters. It is wrapped into the HttpRequest interface, and the request parameters of the request object are obtained through the getParamter() method.

  This object is an instance of the HttpServletRequest interface.

The more important methods are : getAttribute, getParameter, getCookies, getParameterNames, getParameterValues, getSession, setAttribute , getAttributeNames, getMethod, getQueryString, etc.

response

  The object is wrapped into the HttpServletResponse interface. It encapsulates the response generated by the JSP and is then sent to the client in response to the client's request.

  • The more important methods are : addCookie, setContentType, sendRedirect (redirection), flushBuffer, setHeader()
  • Redirection : it will lose all request parameters and request scope attributes, it will generate a second request that is not in the same request scope as the previous one.

pageContext

  The pageContext object is encapsulated into the javax.servlet.pageContext interface, which wraps the page context for the JSP page. Manages access to named objects that belong to a specially visible section in a JSP. Using it you can also access page, request, session, application scoped variables.

The more important methods are : getAttribute (page range), getRequest, getResponse, setAttribute, getServletContext, getSession.

out

  The object is an instance of javax.jsp.JspWriter and provides several methods that you can use to send the output back to the browser.

session

  • The session object is used to save the information of each user in order to track the operation status of each user. The session information is stored in the container,
  • Under normal circumstances, when a user logs in to the system for the first time, the container will assign a unique session id to the user. This ID is used to distinguish other users. When the user logs out of the system (browser), the session will automatically disappear.
  • Session corresponds to the HttpSession interface.

The more important methods are : getAttribute, getAttributeNames, removeAttributes, setAttribute .

config

   The object is encapsulated into javax, servlet.ServletConfig interface, which represents the configuration of Servlet. When a servlet is initialized, the container passes certain information to the servlet through this object.

page

  The object is an instance of the java.lang.Object class. It refers to the instance of the JSP implementation class, that is, it is the JSP itself, through which it can be accessed. Refers to the this object of the servlet

exception

   The object is an instance of the java.lang.Throwable class. It refers to the runtime exception, that is, the result of the error page being called. This object can only be used in error pages (pages with isErrorPage=true in the page directive).

application

  The application object saves information for multiple applications. For a container, each user uses an application object in common, which is different from the session object. After the server starts, the application object is automatically created, and this object will remain until the server is shut down

The more important methods are : setAttribute, getAttribute, getInitParameter , getServletInfo(), getAttributeNames, etc.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325749499&siteId=291194637