Cookies is the concept of storing the client's information in the client machine itself but in the form of a file called as Cookies. So it contains all the information sent by the Web server with the response header. previously all the required information of a client is managed, handled, kept and carried by the server itself. Now with the concept of Cookies all get stored in the client browser in the form a file. So in context of session tracking, session data is transmitted to the client machine and fed in the client browser as a Cookie with all other required information's like domain,server etc. So it makes it client dependent. Whenever a client sends request for a resource to a web server, the cookies having matching information of the requested domain and server also sent to the Web server as a request header so that the session will be maintained for the current active member.

Servlet API has a class named as Cookie which is used to store cookie information from a web server to client machine using addCookie() method. To do so we have to follow few steps.

1. Need to create cookie object with the argumented constructor.

Cookie ck = new Cookie(String, String);

name --> Represents name of the cookie.
value --> Represents value of the cookie.

2. Need to add Cookie in the response object.

res.addCookie(ck); 

Here, " res " is the HttpServletResponse object which is at the service() method of the servlet.

Note : Cookies class is present under the package javax.servlet.http. To get the cookies information from the request header we have a method i.e getCookie() which returns the array of cookie object (Cookie[] ) .

Advantages of cookie

1. It reduces the network traffic and reduces the server responsibility of managing client's information as well.

2. Cookies can able to maintain the client's data, which speed up the request processing.

Disadvantage of cookie 

1. Cookies can be disabled in the clients browser which makes it client dependent.

2. If user deletes the cookies then again session tracking would lead to the failure.

3. Cookies are still not secure, it can be steal using cookies stealing concept.

4. Due to the limited cookie size it cannot store large data's.


0 comments:

Post a Comment

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

Online Members

Live Traffic