javax.servlet.http
Intece HttpServletResponse
All Superinteces:
ServletResponse
All Known Implementing Classes:
HttpServletResponseWrapper
2.HttpServletResponse的API
1)void addCookie(Cookie cookie)
Adds the specified cookie to the response.
2)void addHeader(java.lang.String name, java.lang.String value)
Adds a response header with the given name and value.
3)java.lang.String encodeURL(java.lang.String url)
Encodes the specified URL by including the session ID in it, or, if encoding is not needed, returns the URL unchanged.重写URL,使其携带sessionId.。这是会哈跟踪技术之一。
4)java.lang.String encodeRedirectURL(java.lang.String url)
Encodes the specified URL for use in the sendRedirect method or, if encoding is not needed, returns the URL unchanged.
5)void sendRedirect(java.lang.String location)
Sends a temporary redirect response to the client using the specified redirect location URL and clears the buffer.
注:URL重写
1.如果客户端的浏览器不支持cookie,也可以通过URL重写来实现Session对象的唯一性。可以使用HttpServletResponse的encodeRedirectURL和encodeUrl方法来实现URL重写。
2.所谓的URL重写,就是当客户从一个页面重新连接到另一个页面时,通过向这个新的URL添加参数,把session对象的sessionId传递过去,这样就可以保证同一个客户在该网站各个页面中的session对象是完全相同的。
业务的会话概念:任何业务的请求都是有上下文环境的,而往往上下文环境是受前面业务操作的结果,此时就诞生了会话这个概念..
SESSION是业务会话的技术实现,其中HttpSession是WEB会话的具体实现.
session对象用于在会话范围内,记录每个客户端的访问状态,以便于跟踪每个客户端的操作状态,在会话中存储的信息;在浏览器发出的后续请求时可以获得这些会话的有效数据。session对象所实现的接口为javax.servlet.http Intece HttpSession。
在JSP页面可以直接使用session对象,也可以通过pagecontext.getSession()或者HttpSession的getSession方法来重新获取session对象。
Session是存储于服务器内存当中的会话,我们知道Http是无状态协议,为了支持客户端与服务器之间的交互,我们就需要通过不同的技术为交互存储状态,而这些不同的技术就是Cookie和Session了。
本文来自电脑杂谈,转载请注明本文网址:
http://www.pc-fly.com/a/ruanjian/article-36808-12.html
现在人们买白菜都挑有虫子的