9 large built-in objects in jsp Detailed

A: built-in objects related to interpretation and the kind of

1. The
built-in objects, by definition, is not used in the new object jsp, jsp comes in, can be directly used
2.
jsp 9 has a large built-in objects, namely:
request object: request
output object: out
in response to: response
application objects: application
session object: session
page context object: pageContext
page object: page
configuration object: config
exception object: exception




Two: Detailed where several important things built-in objects

(A) Request
(. 1) Request: Scope: only one request, the requested object, the client sends the storage request information to the server
9 large built-in objects in jsp Detailed


(2) request the object common methods:
String the getParameter (String name): The name request field Key, return the value of the field value
String [] the getParameterValues (String name): The name request field Key, a plurality of field values return value
void setCharacter Encoding: Set request encoding (encoding format "UTF-. 8")
. the getRequestDispatcher ( "b.jsp,") forward (request, Response): requesting a page forward bar-shaped A-> B
getServerContext (); object items acquired ServerContext


(3) of the page jump - the difference between forward and redirect request
forwarding and redirection can be achieved jump page:
Forwarding: request.getRequestDispatcher ( "url") forward (request, response).
Redirects: response. sendRedirect ( "url")

Request forwarding

9 large built-in objects in jsp Detailed

Redirect

9 large built-in objects in jsp Detailed


(4) the difference between forwards the request to redirect
1, forwarded using request.getRequestDispatcher () method; redirection using response.sendRedirect ();
2, Forward: browser URL address bar unchanged. Redirect: change the browser URL address bar of;
3, forwarding an internal server behavior, redirect the client behavior;
4, transponder is a browser made only one access request. Redirect the browser to do at least two access requests;
5, can carry forward data, information is not lost; redirection can not carry parameters, information will be lost (request scope).
6, forwarding only forwards inside the server; there is no limit to redirect


(Ii) the session (session)
(. 1) to explain the session

Session: Session technologies, from client opens a browser to access the server, the client finally close the browser, the whole process is called a session.
In the course of this session, the server creates a unique temporary container and associated client for each client, all the information stored in this container for the current customer.
And when the response data to the client, the client will send back a unique id identifies the current client-related temporary container, the next time the customer accesses the server end, carries this id information, can be found on the server side temporary Rong and client-related, continue to use the temporary container.
If you get the Session object for each client service: You can get a unique Session object, and the current client-related by the Request object in the servlet. Can be used directly in the jsp


(2) the timing of the destruction session
1, generally in the web server has a default Session of survival time, usually half an hour. If within 30 minutes, the user has not done anything, then the current Session of the automatic destruction of the server.
2, does not shut down the server properly. Normal shut down the server, the server will use the Session object serialization technique io stream stored in tomcat / work directory
3, the destruction of the Servlet Session object program manually. ; the session.invalidate ()
: survival time of the Session web.xml configuration can also be specified by a process
// in seconds, is generally performed when the stored value set; setMaxInactiveInterval (int interval).


(3) the link between session and cookie (examples explain)
9 large built-in objects in jsp Detailed

9 large built-in objects in jsp Detailed
9 large built-in objects in jsp Detailed


(3)cookie的介绍
1.
Cookie技术主要需要依赖于给用户响应数据时,给用户的本地写数据。
创建一个 cookie,cookie 是 servlet 发送到 Web 浏览器的少量信息,这些信息由浏览器保存,然后发送回服务器。cookie 的值可以唯一地标识客户端,因此 cookie 常用于会话管理。
Cookie技术主要解决的是在客户端和服务器进行交互的过程中,保存用户的数据,这些数据主要是通过服务器使用Cookie对象写到客户端的浏览器中。然后在浏览器中保存这些数据。Cookie对象可以保存用户和服务器的交互数据,但是需要保存在客户端。

2
获取cookie
需要使用HttpServletRequest对象中的getCookies方法,会得到一个Cookie数组,这是因为一个站点可能会存放多个Cookie数据
例如:Cookie[] cookies = request.getCookies();
得到Cookie数组之后,判断cookies数组是否存在 cookies == null,如果cookies存在,根据cookie的name去查找指定cookie

3.
Send cookie
After creating Cookie object, you need to use addCookie method of HttpServletResponse, Cookie object is added to the response, and then sent to the client.
For example: response.addCookie (cookie);
providing a Cookie object Cookie getName key value may be acquired, there is provided getValue key values may be obtained corresponding to the value, but also can be used setValue to the current target set value Cookie value.
SetPsth set a cookie can access the resource path
SetMaxAge () - Set the cookie lifetime


(4)
the difference between the session and cookie

Note: cookie than nine built-in objects

Since one cookie instead of nine built-in objects, so when using the cookie, must be new
a cookie object
9 large built-in objects in jsp Detailed


(C) application

Global Variables: valid during the entire project run (switch browsers, still valid), but shut down the server or access other items will not work
9 large built-in objects in jsp Detailed


Comparison (d) three objects

9 large built-in objects in jsp Detailed

Guess you like

Origin blog.51cto.com/14441795/2422160