首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

javax.servlet.http.Cookie 相干

2012-11-04 
javax.servlet.http.Cookie 相关本文转载自:http://lavasoft.blog.51cto.com/62575/78163?public class?Co

javax.servlet.http.Cookie 相关

本文转载自:http://lavasoft.blog.51cto.com/62575/78163

?

public class?Cookie
extends java.lang.Object
implements java.lang.CloneableCreates a cookie, a small amount of information sent by a servlet to a Web browser, saved by the browser, and later sent back to the server. A cookie's value can uniquely identify a client, so cookies are commonly used for session management. 创建一个cookie,一个小量信息通过Servlet发送给Web浏览器,通过浏览器保存,以后再从浏览器发送给服务器。一个cookie的值能唯一识别一个客户端,因此cookie常用于session的管理。A cookie has a name, a single value, and optional attributes such as a comment, path and domain qualifiers, a maximum age, and a version number. Some Web browsers have bugs in how they handle the optional attributes, so use them sparingly to improve the interoperability of your servlets. 一个cookie有一个名字和一个值和一些可选择的属性例如注释、路径、域、最大有效时间、版本号等。一些浏览器在处理可选项时有bug,因此应保守使用以提高sevlet的交互性。The servlet sends cookies to the browser by using theHttpServletResponse.addCookie(javax.servlet.http.Cookie)?method, which adds fields to HTTP response headers to send cookies to the browser, one at a time. The browser is expected to support 20 cookies for each Web server, 300 cookies total, and may limit cookie size to 4 KB each. Sevlet发送cookie使用HttpServletResponse.addCookie(javax.servlet.http.Cookie)方法,一个浏览器预计最多可支持300个cookie,对一个站点最多支持20个cookie,并且可能限制一个cookie的大小不超过4KB。The browser returns cookies to the servlet by adding fields to HTTP request headers. Cookies can be retrieved from a request by using the?HttpServletRequest.getCookies()?method. Several cookies might have the same name but different path attributes. 浏览器通过HTTP请求的处理者返回cookie到一个servlet。cookie能被从HttpServletRequest.getCookies()中重新获取到。Cookies affect the caching of the Web pages that use them. HTTP 1.0 does not cache pages that use cookies created with this class. This class does not support the cache control defined with HTTP 1.1. Cookie影响每一个使用它的web页。 (......)This class supports both the Version 0 (by Netscape) and Version 1 (by RFC 2109) cookie specifications. By default, cookies are created using Version 0 to ensure the best interoperability. 这个类同时支持版本0和版本1的cookie规范。默认情况下,cookie使用版本0来创建以确保最好的交互性。
?java.lang.Objectclone()?
??????????Overrides the standard?java.lang.Object.clone?method to return a copy of this cookie. 返回cookie克隆的副本,这个方法覆盖了java.lang.Object.clone()方法。?java.lang.StringgetComment()?
??????????Returns the comment describing the purpose of this cookie, or?null?if the cookie has no comment.返回一个描述cookie用途的注释,如果没有注释,则返回null。?java.lang.StringgetDomain()?
??????????Returns the domain name set for this cookie.返回一个cookie域名。(域名指定cookie在哪个域中有效,例如:Domain=.blog.51cto.com)?intgetMaxAge()?
??????????Returns the maximum age of the cookie, specified in seconds, By default,?-1?indicating the cookie will persist until browser shutdown. 返回cookie在客户端最大的有效时间,以秒为单位。默认情况下为-1,表示cookie将一直有效直到浏览器关闭。?java.lang.StringgetName()?
??????????Returns the name of the cookie.返回cookie的名字。?java.lang.StringgetPath()?
??????????Returns the path on the server to which the browser returns this cookie.返回cookie对服务器上哪个url有效。?booleangetSecure()?
??????????Returns?true?if the browser is sending cookies only over a secure protocol, or?false?if the browser can send cookies using any protocol. 如果浏览器仅仅安全协议下发送cookie则返回true。浏览器能使用任何协议发送cookie则返回fasle。?java.lang.StringgetValue()?
??????????Returns the value of the cookie. 返回cookie的值。?intgetVersion()?
??????????Returns the version of the protocol this cookie complies with.返回cookie内容所遵循的版本。(目前只有值为1时可用)。?voidsetComment(java.lang.String?purpose)?
??????????Specifies a comment that describes a cookie's purpose.设置描述cookie用途的注释。?voidsetDomain(java.lang.String?pattern)?
??????????Specifies the domain within which this cookie should be presented.设置cookie在哪一个域中使用。?voidsetMaxAge(int?expiry)?
??????????Sets the maximum age of the cookie in seconds.设置cookie最大的有效时间。?voidsetPath(java.lang.String?uri)?
??????????Specifies a path for the cookie to which the client should return the cookie.设置cookie的有效路径。?voidsetSecure(boolean?flag)?
??????????Indicates to the browser whether the cookie should only be sent using a secure protocol, such as HTTPS or SSL.设置是否使用安全协议如HTTPS或SSL等发送cookie。?voidsetValue(java.lang.String?newValue)?
??????????Assigns a new value to a cookie after the cookie is created. 给一个cookie重新指定一个新值。?voidsetVersion(int?v)?
??????????Sets the version of the cookie protocol this cookie complies with.设置cookie使用的协议版本。?  

热点排行