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.


Related Posts:

  • Servlet Attributes Sevlet Attributes are the functionality given to have communication between servlet to servlet/jsp or jsp to servlet/jsp. Attributes can be used with the request object or session object, both are having different scopes o… Read More
  • forward() in servlet forward() is a method in RequestDispatcher interface which is used to dispatch the control from a servlet to another servlet/jsp. Container is responsible to dispatch the the control by finding the full path internally eith… Read More
  • RequestDispatcher with ServletContext We can get the RequestDispatcher object with the ServletContext simpley by calling getRequestDispatcher(String url) with the ServletContext object which finally returns the RequestDispatcher object. We have two possible opt… Read More
  • include() in servlet include() is a method defined in the RequestDispatcher interface with ServletRequest and ServletResponse as a parameter. It is same as forward with slight difference of storing the content of both source and target resourc… Read More
  • RequestDispatcher with Request object We can get RequestDispatcher object with HttpServletRequest object by calling getRequestDispatcher(String url) and passing the url as a String paramter but its not mandatory to start with " / " as it was in case of ServletC… Read More

0 comments:

Post a Comment

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

201976

Online Members

Live Traffic