cookie的ppt

幻灯片 9 .O {color:black; font-size:149%;} .O1 {color:black; font-size:149%;} .O2 {color:black; font-size:149%;} a:link {color:#CB00CB !important;} a:active {color:#3300FF !important;} a:visited {color:#0098CB !important;} <!--.sld {left:0px !important; width:6.0in !important; height:4.5in !important; font-size:103% !important;} -->

n A cookie is a small bit of text sent to the client that can be read again later
n Limitations (for the protection of the client):
n Not more than 4KB per cookie (more than enough in general)
n Not more than 20 cookies per site(一个站点的cookie不能超过20个)
n Not more than 300 cookies total(一个浏览器不超过300个)
n Cookies are not a security threat
n Cookies can be a privacy threat
n Cookies can be used to customize advertisements
n Outlook Express allows cookies to be embedded in email
n A servlet can read your cookies
n Incompetent companies might keep your credit card info in a cookie
n Netscape and Firefox let you refuse cookies to sites other than that to which you connected

Using Cookies

幻灯片 10 .O {color:black; font-size:149%;} .O1 {color:black; font-size:149%;} .O2 {color:black; font-size:149%;} a:link {color:#CB00CB !important;} a:active {color:#3300FF !important;} a:visited {color:#0098CB !important;} <!--.sld {left:0px !important; width:6.0in !important; height:4.5in !important; font-size:103% !important;} -->
n import javax.servlet.http.*;
n Constructor: Cookie(String name, String value)
n Assuming request is an HttpServletRequest and response is an HttpServletResponse ,
n response .addCookie(cookie);
n Cookie[ ] cookies = request .getCookies();
n String name = cookies[i].getName();
n String value = cookies[i].getValue();
n There are, of course, many more methods in the HttpServletRequest , HttpServletResponse , and
Cookie classes in the javax.servlet.http package

幻灯片 11 .O {color:black; font-size:149%;} a:link {color:#CB00CB !important;} a:active {color:#3300FF !important;} a:visited {color:#0098CB !important;} <!--.sld {left:0px !important; width:6.0in !important; height:4.5in !important; font-size:103% !important;} -->
Some more Cookie methods

幻灯片 11 .O {color:black; font-size:149%;} .O1 {color:black; font-size:149%;} a:link {color:#CB00CB !important;} a:active {color:#3300FF !important;} a:visited {color:#0098CB !important;} <!--.sld {left:0px !important; width:6.0in !important; height:4.5in !important; font-size:103% !important;} -->
n public void setComment(String  purpose )
n public String getComment()
n public void setMaxAge(int  expiry )
n public int getMaxAge()
n Max age in seconds after which cookie will expire
n If expiry is negative, delete when browser exits
n If expiry is zero, delete cookie immediately
n setSecure(boolean  flag )
n public boolean getSecure()
n Indicates to the browser whether the cookie should only be sent using a secure protocol, such as HTTPS or SSL

幻灯片 12 .O {color:black; font-size:149%;} a:link {color:#CB00CB !important;} a:active {color:#3300FF !important;} a:visited {color:#0098CB !important;} <!--.sld {left:0px !important; width:6.0in !important; height:4.5in !important; font-size:103% !important;} -->
What cookies are good for
幻灯片 12 .O {color:black; font-size:149%;} .O1 {color:black; font-size:149%;} .O2 {color:black; font-size:149%;} a:link {color:#CB00CB !important;} a:active {color:#3300FF !important;} a:visited {color:#0098CB !important;} <!--.sld {left:0px !important; width:6.0in !important; height:4.5in !important; font-size:103% !important;} -->
n Advantages:
n Java’s Session Tracking API (to be discussed) makes cookies dead simple to use
n Cookies can easily contain more data than hidden fields
n Data is stored on the client computer, not on yours
n This saves space on the server
n May let you avoid keeping track of multiple(session) data structures
n Disadvantages:
n Data is stored on the client computer, not on yours
n This means the data is neither safe nor secure
n Should not be used for user data--cookies may be discarded or the user may contact the server from another computer
n Users can tell their browser to turn cookies off

幻灯片 12 .O {color:black; font-size:149%;} a:link {color:#CB00CB !important;} a:active {color:#3300FF !important;} a:visited {color:#0098CB !important;} <!--.sld {left:0px !important; width:6.0in !important; height:4.5in !important; font-size:103% !important;} -->
n Cookies are good for keeping session data, not user data

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值