PageContext

xiaoxiao2021-03-06  20

PageContext hidden objects correspond to the object of javax.servlet.jsp.pageContext type, the implied object is automatically added to PageContext, and you can get the servlet object corresponding to the JSP-related implicit object, Like getRequest () can get servletRequest, getServletConfig () can get servletconfig, getsession () can get httpsession, etc. The servlet object that provides the hidden object is not the main role of PageContext. Its main feature is providing a single interface to manage a variety of public objects (like httpsession, servletcontext, servletconfig, servletRequest, servletresponse, etc.), Provide a single API to manage properties scope, and more. We have previously used SetAttribute () such as session to set the properties object that the process can share, using the properties set by the session can be shared in the same process, except for the session, there is PageContext, Request, Application is also You can use the method such as SetAttribute () (see the API file for details) to set the property object that can be shared, but the attribute set by these four objects is different. Using the attribute object set by PageContext, the shared range is limited to the same JSP page, using the property object set by Request, which can share (including Forward to other JSP pages), the session object set during the same request processing. The attribute object is limited to the same process, and the properties set by the Application object, the JSP pages in the entire web application can be shared. The following will take Application as an example, you can set some objects to the Application when the property is set to the Application, and another JSP page can obtain this property object when appropriate, for example: <% string attr = "string object"; OUT. Println ("Setting Properties to Application:" Attr); Application.settribute ("Str", Attr);%> We first connect this JSP page to execute the property setting, then we connect this JSP page: < % String attr = (string) Application.getaTRibute ("str"); out.println ("gets the application attribute: attr);%> Because we have set string objects as an attribute in Application, we have You can get the previously set objects in this page, the same truth, you can also use the same way to set the properties to PageContext, Request, Session, etc., as long as in the allowable scope, you can get the set set. Attribute object.

转载请注明原文地址:https://www.9cbs.com/read-39578.html

New Post(0)