Play with Cookies using Scala and Lift

As we know , Cookie is a small piece of data which is sent from a website and stored in a user’s web browser while a user is browsing a website. Next time , when user browses , cookie can be retrieved . Cookies are essentially a token of string data that is stored on the user’s machine.
In this section , I will explain how easily you can play with cookies using Lift web framework and Scala language . Lift is an expressive and elegant framework for writing web applications. Lift provides its own Cookie support (rather than using underlying Servlet cookie support) . Using Cookies in Lift is very easy.

import net.liftweb.http.S

Add Cookie :

 S.addCookie(HTTPCookie("cookie Name", "cookie Value").setDomain(S.hostName).setPath("/")) 

Note: If you are trying to add a cookie with an existing cookie name , it will overwrite that cookie .
Delete Cookie :

S.deleteCookie("cookie Name")

Fetch Cookie :
If you want cookie with a given name :

 S.findCookie("cookie Name")

If you want list of cookies , which will be sent in the response :


About Ayush Mishra

Ayush is the Sr. Software Consultant @ Knoldus Software LLP. In his 5 years of experience he has become developer with proven experience in architecting and developing web applications. Ayush has a Masters in Computer Application from U.P. Technical University, Ayush is a strong-willed and self-motivated professional who takes deep care in adhering to quality norms within projects. He is capable of managing challenging projects with remarkable deadline sensitivity without compromising code quality. .
This entry was posted in Java, Scala, Web. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s