17 soft work 2 shifts Ningyi Jian JAVAWEB knowledge test paper notes summary

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/xixihahah574/article/details/102667249

1, the parameter acquisition request method ------> getParameter ()
Gets Request Scope parameter method -------> getAttribute () (take)
--------> the setAttribute () (memory )
--------> removeAttribute () (remove)

the request.getAttribute (String name); return type of Object, remember to turn strong

** 2, get ServletContext

this.getServletContext ();
this.getServletConfig () GetServletContext ();.
the HttpSession this method also, request.session.getServletContext () **;
a WEB application all share the same Servlet ServletContext object.

** 3, get ServletConfig

ServletConfig config = this.getServletConfig (); **
mainly for loading the servlet initialization parameters. In a web application may present a plurality ServletConfig object (a ServletConfig object corresponding to a Servlet)

4、cookie和session

(1) cookie
1.cookie.setMaxAge (-1): maxAge default cookie attribute value is -1, which survived only in the browser memory. Once you close the browser window, the cookie will disappear.
2.cookie.setMaxAge (60 * 60): indicate the cookie object can survive for 1 hour. When life is greater than 0, Cookie browser will be saved to the hard drive, even if you close your browser, even restart the client computer, cookie would survive one hour;
3.cookie.setMaxAge (0): the cookie life equal to 0 is a special the value that represents the cookie is invalid! That is, if the original browser has saved the Cookie, you can delete this by setMaxAge Cookie Cookie's (0). Whether in the browser memory, or hard disk on the client will delete the Cookie

(2) session
1.int getMaxInactiveInterval (): Gets session can be a maximum time of inactivity (seconds), the default is 30 minutes. When the session is not used within 30 minutes, then the session will be removed Tomcat this pool session;
2.void the setMaxInactiveInterval (interval The int): setting the maximum allowable session inactivity time (seconds), if set to 1 second, as long as session is not used within one second, then the session will be removed;

5.JSP nine built-in objects

Created in the JSP to 9 without objects can be used are:
L OUT (the JspWriter): sending text data to the client response.getWriter equivalent to (), is used;
L config (the ServletConfig): corresponds to "Mami" in the ServletConfig;
L page (Mami type of the current JSP's): the current JSP pages of "this", that is, the current object;
L pageContext (pageContext): page context object;
L Exception (Throwable): only available in error page this object;
L Request (HttpServletRequest):; Object i.e. HttpServletRequest class
: Object i.e. HttpServletResponse class; L Response (HttpServletResponse)
L file application (ServletContext):; Object i.e. ServletContext class
: Object i.e. HttpSession class l session (HttpSession) not every JSP page can be used, if you set <session = "false"%% @ page> in a JSP page, indicating that the page can not use the session.

6, the four scopes

page (JSP active) Request (request time) the session (a session) file application (current web application) in ascending
page domain refers to the pageContext.
Request field refers to the HttpServletRequest
the session domain refers to the HTTPSession
file application domain refers ServletContext
the reason why they are the domain object, simply because they have built-in map collection has setAttribute getAttribute method. And their name is of type String, and the value is of type Object.
They have their own life cycle and fixed scope

**

7, listener

**
ServletContextListener -----> two methods to create and monitor the demise
ServletContextAttributeListener -----> three methods, listens to add, modify, replace, remove it.
HttpSessionListener -----> two methods to create and monitor the demise
HttpSessioniAttributeListener -----> three methods, listens to add, modify, replace, remove it.
ServletRequestListener -----> two methods to create and monitor the demise
ServletRequestAttributeListener -----> three methods, listens to add, modify, replace, remove it.

Unusual two:
HttpSessionActivationListener;
the HTTP interface listening sessions active and passivate. This interface provides the following three methods
1.attributeAdded (HttpSessionBindingEvent event);
when a subject in a range join the session, the notification is listening object
2.attributeReplaced (HttpSessionBindingEvent event);
when a subject in the scope of the session another object substituent , notice is listening objects.
3.attributeRemoved (HttpSessionBindingEvent event);
When the session object from a subject in the scope of substituted another object, wherein the object is listening notification HttpSessionBindingEvent three principal methods: getName (), getSession () and the getValue ()
HttpBindingListener;
interface listening HTTP session object tie specific information. It is the only need to set the Listener in the web.xml. This interface provides the following two methods
1.valueBound (HttpSessionBindingEvent event);
when a subject in the scope of the session will be added automatically invoked
2.valueUnBound (HttpSessionBindingEvent event);
would have when the object is removed from the range of the session is automatically transfer

Guess you like

Origin blog.csdn.net/xixihahah574/article/details/102667249