- Increase transparency
- Onboard new hires faster
- Access from mobile/offline
There are 2 types of cookies in servlets.
It is valid for single session only. It is removed each time when user closes the browser.
It is valid for multiple session . It is not removed each time when user closes the browser. It is removed only if user logout or signout.
Note: Gmail uses cookie technique for login. If you disable the cookie, gmail won't work
Cookies are maintained at client sideEven though they are maintained at client side is it not server adding cookie to to browser using response as explained below
Introduction to Servlet
What is Servlet Servlet Terminology Servlet API Servlet Interface GenericServlet HttpServlet Servlet Life Cycle Servlet Example How servlet works? War File welcome-file-list Load on startup
Servlet with IDE
servlet in Eclipse servlet in Myeclipse servlet in Netbeans
Attribute in Servlet
Session Techniques 1) Cookies in Servlet Cookies: Login & Logout 2) Hidden Form Field 3) URL Rewriting 4) HttpSession Session: Login & Logout
Event and Listener
What is Filter Authentication Filter FilterConfig Useful examples
ServletInputStream ServletOutputStream Annotation Servlet SingleThreadModel SSI
Registration Example Fetching records Improving Performance Uploading file Downloading file Servlet Sending Email Write data to PDF Login Example Writing Image
Servlet Quiz(Part-1) Servlet Quiz(Part-2) Servlet Quiz(Part-3)
Cookies in Servlet
A cookie is a small piece of information that is persisted between the multiple client requests.
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.
How Cookie works
By default, each request is considered as a new request. In cookies technique, we add cookie with response from the servlet. So cookie is stored in the cache of the browser.
How to delete Cookie?
Let's see the simple code to delete cookie. It is mainly used to logout or signout the user.
Cookie ck=new Cookie("user","");//deleti
ng value of cookie
the maximum age to 0 seconds
dding cookie in the response
Simple example of Servlet Cookies
In this example, we are storing the name of the user in the cookie object and accessing it in another servlet. As we know well that session corresponds to the particular user. So if you access it from too many browsers with different values, you will get the different value.
. So if you access it from too many browsers with different values, you will get the different value.
|unix in java example||9||43|
|Java passing arguments (type error)||2||35|
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
10 Experts available now in Live!