SlideShare a Scribd company logo
Enterprise Java
Unit-2
Chapter-2
• Cookies
By
Prof. Sandeep Vishwakarma
Cookies
• Hyper Text Transfer Protocol [HTTP]
does not maintain a persistent connection.
Each request made by a Web browser is
made using a new connection. Hence this
protocol does not maintain state across
HTTP requests, so cookies are used.
• Cookies are small text files that are
created by a server side program such as
a Servlet run at the Web server.
Cookies Parameters
• cookie has 6 parameters .
1. The name of the cookie
2. The value of the cookie
3. The expiration date of the cookie
4. The path the cookie is valid for
5. The domain the cookie is valid for
6. The need for a secure connection to
exist to use the cookie
Where cookies are used:
• Cookies are most commonly used to track website
activity. When you visit some sites, the server gives
you a cookie that acts as your identification card
• Cookies are also used for online shopping .Online
stores often use cookies that record any personal
information you enter, as well as any items in your
electronic shopping cart, so that you don't need to
re-enter this information each time you visit site.
• Servers can use cookies to provide personalized web
pages. When you select preferences at a site that
uses this option, the server places the information in
a cookie.
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. After that if request is sent by
the user, cookie is added with request by default.
Thus, we recognize the user as the old user.
Types of Cookies
There are two types of cookies:
 Permanent / Persistent Cookies
 Session / Transient Cookies
Permanent / Persistent Cookies
Permanent cookies are those cookies that are stored
on a user’s computer and are not deleted when the
browser is closed. Permanent cookies can retain user
preferences for a particular website, allowing those
preferences to be used in all future browsing sessions.
Permanent cookies can be used to identify individual
users, so that the website can analyze the user’s
surfing behaviour within the website. Cookies can also
be used to provide site information such as the
number of visitors, the average time spent on a
particular page and generally the performance of the
website.
Session / Transient Cookies
Session or Transient cookies are those cookies that are
stored in the computer’s memory only during a user’s
browsing session and are automatically deleted from the
user’s computer when the Web browser is closed.
Those cookies usually store a session ID that is not
permanently bound to the user, allowing the user to move
from page to page without having to login repeatedly. They
are widely used by commercial websites [for example, to
keep track of items that a consumer has added to a
shopping cart].
Session cookies are never written on the hard drive and
they do not collect any information from the user’s
computer. Session cookies expire at the end of the user’s
browser session.
Creating Cookies Using Servlet
• Following pages are used for creating cookies
1. index.html
2. FirstServlet.java
3. SecondServlet.java
index.html
</html>
<body>
<form action="FirstServlet" method="post" >
<input type="text" name="userName">
<input type="submit" value="submit">
</form>
</body>
</html>
FirstServlet.java
public class FirstServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter())
{
String n=request.getParameter("userName");
out.println("Welcome" +n);
Cookie ck=new Cookie("uname", n);
response.addCookie(ck);
out.print("<form action='SecondServlet' method='post'>");
out.print("<input type='submit' value='submit'>");
out.print("</form>");
} }
SecondServlet.java
public class SecondServlet extends HttpServlet
{
protected void processRequest(HttpServletRequest
request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter())
{
Cookie ck[]=request.getCookies();
out.print("Hello" +ck[0].getValue());
out.close();
} }
Output Screen
Dynamically Changing the Colors of A Page
Following pages are used:
• Index.html
• DynamicServlet.java
Index.html
<HTML>
<HEAD>
<TITLE>Color Change</TITLE>
</HEAD>
<BODY>
<FORM method=get action="DynamicServlet" method="post">
<CENTER>
Select Color :
<select name="color" id="color">
<option value="red">Red</option>
<option value="green">Green</option>
<option value="blue">Blue</option>
<option value="yellow">yellow</option>
<option value="black">Black</option>
</Select>
<input type="submit" value="Submit">
</FORM>
</BODY> </HTML>
DynamicServlet.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter())
{
String c=request.getParameter("color");
if(c.equals("red"))
out.println("<body BGCOLOR=red>");
if(c.equals("green"))
out.println("<body BGCOLOR=green>");
if(c.equals("green"))
out.println("<body BGCOLOR=green>");
if(c.equals("blue"))
out.println("<body BGCOLOR=blue>");
if(c.equals("yellow"))
out.println("<body BGCOLOR=yellow>");
if(c.equals("black"))
out.println("<body BGCOLOR=black>");
out.println("<center><h2>The selected color is:"+c+"</h2></center>");;
out.close(); } }
Output Screen
Thank You

More Related Content

What's hot

Session bean
Session beanSession bean
Session bean
sandeep54552
 
jstl ( jsp standard tag library )
jstl ( jsp standard tag library )jstl ( jsp standard tag library )
jstl ( jsp standard tag library )
Adarsh Patel
 
Jsp with mvc
Jsp with mvcJsp with mvc
Jsp with mvc
vamsitricks
 
An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST
Ram Awadh Prasad, PMP
 
Java Servlet
Java ServletJava Servlet
Java Servlet
Yoga Raja
 
Servlet life cycle
Servlet life cycleServlet life cycle
Servlet life cycle
Venkateswara Rao N
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
Kasun Madusanke
 
ASP.NET - Life cycle of asp
ASP.NET - Life cycle of aspASP.NET - Life cycle of asp
ASP.NET - Life cycle of asp
priya Nithya
 
Tomcat
TomcatTomcat
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
David Gómez García
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
Tanmoy Barman
 
Servlets
ServletsServlets
Servlets
ZainabNoorGul
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
Bharat_Kumawat
 
Servlets
ServletsServlets
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
Adnan Sohail
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
Sam Brannen
 
Servlet and Servlet Life Cycle
Servlet and Servlet Life CycleServlet and Servlet Life Cycle
Servlet and Servlet Life Cycle
Dhrumil Panchal
 
ASP.NET Brief History
ASP.NET Brief HistoryASP.NET Brief History
ASP.NET Brief History
Sudhakar Sharma
 
Web services SOAP
Web services SOAPWeb services SOAP
Web services SOAP
princeirfancivil
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
Vikas Jagtap
 

What's hot (20)

Session bean
Session beanSession bean
Session bean
 
jstl ( jsp standard tag library )
jstl ( jsp standard tag library )jstl ( jsp standard tag library )
jstl ( jsp standard tag library )
 
Jsp with mvc
Jsp with mvcJsp with mvc
Jsp with mvc
 
An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST An Overview of Web Services: SOAP and REST
An Overview of Web Services: SOAP and REST
 
Java Servlet
Java ServletJava Servlet
Java Servlet
 
Servlet life cycle
Servlet life cycleServlet life cycle
Servlet life cycle
 
Java Server Pages
Java Server PagesJava Server Pages
Java Server Pages
 
ASP.NET - Life cycle of asp
ASP.NET - Life cycle of aspASP.NET - Life cycle of asp
ASP.NET - Life cycle of asp
 
Tomcat
TomcatTomcat
Tomcat
 
Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.Java 8 Stream API. A different way to process collections.
Java 8 Stream API. A different way to process collections.
 
JDBC: java DataBase connectivity
JDBC: java DataBase connectivityJDBC: java DataBase connectivity
JDBC: java DataBase connectivity
 
Servlets
ServletsServlets
Servlets
 
Ajax presentation
Ajax presentationAjax presentation
Ajax presentation
 
Servlets
ServletsServlets
Servlets
 
Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)Asynchronous JavaScript & XML (AJAX)
Asynchronous JavaScript & XML (AJAX)
 
Spring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. RESTSpring Web Services: SOAP vs. REST
Spring Web Services: SOAP vs. REST
 
Servlet and Servlet Life Cycle
Servlet and Servlet Life CycleServlet and Servlet Life Cycle
Servlet and Servlet Life Cycle
 
ASP.NET Brief History
ASP.NET Brief HistoryASP.NET Brief History
ASP.NET Brief History
 
Web services SOAP
Web services SOAPWeb services SOAP
Web services SOAP
 
Jsp ppt
Jsp pptJsp ppt
Jsp ppt
 

Similar to Enterprise java unit-2_chapter-2

Cookie testing
Cookie testingCookie testing
Cookie testing
BugRaptors
 
Sessions&cookies
Sessions&cookiesSessions&cookies
Sessions&cookies
Tirthika Bandi
 
Using cookies and sessions
Using cookies and sessionsUsing cookies and sessions
Using cookies and sessions
Nuha Noor
 
Cookies in servlet
Cookies in servletCookies in servlet
Cookies in servlet
chauhankapil
 
Session,cookies
Session,cookiesSession,cookies
Session,cookies
rkmourya511
 
Module-5_WTA_Managing State & jQuery
Module-5_WTA_Managing State & jQueryModule-5_WTA_Managing State & jQuery
Module-5_WTA_Managing State & jQuery
SIVAKUMAR V
 
Cookies: A brief Introduction
Cookies: A brief IntroductionCookies: A brief Introduction
Cookies: A brief Introduction
HTS Hosting
 
Session tracking in servlets
Session tracking in servletsSession tracking in servlets
Session tracking in servlets
vishal choudhary
 
State Management.pptx
State Management.pptxState Management.pptx
State Management.pptx
DrMonikaPatel2
 
Authentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptxAuthentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptx
Knoldus Inc.
 
Session and cookies,get and post methods
Session and cookies,get and post methodsSession and cookies,get and post methods
Session and cookies,get and post methods
baabtra.com - No. 1 supplier of quality freshers
 
Session and cookies,get and post
Session and cookies,get and postSession and cookies,get and post
Session and cookies,get and post
baabtra.com - No. 1 supplier of quality freshers
 
Session and Cookies.pdf
Session and Cookies.pdfSession and Cookies.pdf
Session and Cookies.pdf
HamnaGhani1
 
PHP COOKIES AND SESSIONS
PHP COOKIES AND SESSIONSPHP COOKIES AND SESSIONS
PHP COOKIES AND SESSIONS
Degu8
 
Web Browser-add ons.pptx
Web Browser-add ons.pptxWeb Browser-add ons.pptx
Web Browser-add ons.pptx
kkmodi12
 
Cookies: HTTP state management mechanism
Cookies: HTTP state management mechanismCookies: HTTP state management mechanism
Cookies: HTTP state management mechanism
Jivan Nepali
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
Sukrit Gupta
 
A Comprehensive Guide to Cookie Management Using HeadSpin's Cutting-Edge Remo...
A Comprehensive Guide to Cookie Management Using HeadSpin's Cutting-Edge Remo...A Comprehensive Guide to Cookie Management Using HeadSpin's Cutting-Edge Remo...
A Comprehensive Guide to Cookie Management Using HeadSpin's Cutting-Edge Remo...
kalichargn70th171
 
Php 07-cookies-sessions
Php 07-cookies-sessionsPhp 07-cookies-sessions
Php 07-cookies-sessions
YUSRA FERNANDO
 
C# cookieless session id and application state
C# cookieless session id and application stateC# cookieless session id and application state
C# cookieless session id and application state
Malav Patel
 

Similar to Enterprise java unit-2_chapter-2 (20)

Cookie testing
Cookie testingCookie testing
Cookie testing
 
Sessions&cookies
Sessions&cookiesSessions&cookies
Sessions&cookies
 
Using cookies and sessions
Using cookies and sessionsUsing cookies and sessions
Using cookies and sessions
 
Cookies in servlet
Cookies in servletCookies in servlet
Cookies in servlet
 
Session,cookies
Session,cookiesSession,cookies
Session,cookies
 
Module-5_WTA_Managing State & jQuery
Module-5_WTA_Managing State & jQueryModule-5_WTA_Managing State & jQuery
Module-5_WTA_Managing State & jQuery
 
Cookies: A brief Introduction
Cookies: A brief IntroductionCookies: A brief Introduction
Cookies: A brief Introduction
 
Session tracking in servlets
Session tracking in servletsSession tracking in servlets
Session tracking in servlets
 
State Management.pptx
State Management.pptxState Management.pptx
State Management.pptx
 
Authentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptxAuthentication in Svelte using cookies.pptx
Authentication in Svelte using cookies.pptx
 
Session and cookies,get and post methods
Session and cookies,get and post methodsSession and cookies,get and post methods
Session and cookies,get and post methods
 
Session and cookies,get and post
Session and cookies,get and postSession and cookies,get and post
Session and cookies,get and post
 
Session and Cookies.pdf
Session and Cookies.pdfSession and Cookies.pdf
Session and Cookies.pdf
 
PHP COOKIES AND SESSIONS
PHP COOKIES AND SESSIONSPHP COOKIES AND SESSIONS
PHP COOKIES AND SESSIONS
 
Web Browser-add ons.pptx
Web Browser-add ons.pptxWeb Browser-add ons.pptx
Web Browser-add ons.pptx
 
Cookies: HTTP state management mechanism
Cookies: HTTP state management mechanismCookies: HTTP state management mechanism
Cookies: HTTP state management mechanism
 
Cookies and sessions
Cookies and sessionsCookies and sessions
Cookies and sessions
 
A Comprehensive Guide to Cookie Management Using HeadSpin's Cutting-Edge Remo...
A Comprehensive Guide to Cookie Management Using HeadSpin's Cutting-Edge Remo...A Comprehensive Guide to Cookie Management Using HeadSpin's Cutting-Edge Remo...
A Comprehensive Guide to Cookie Management Using HeadSpin's Cutting-Edge Remo...
 
Php 07-cookies-sessions
Php 07-cookies-sessionsPhp 07-cookies-sessions
Php 07-cookies-sessions
 
C# cookieless session id and application state
C# cookieless session id and application stateC# cookieless session id and application state
C# cookieless session id and application state
 

More from sandeep54552

Dijkstra Searching Algorithms Shortest.pptx
Dijkstra Searching Algorithms Shortest.pptxDijkstra Searching Algorithms Shortest.pptx
Dijkstra Searching Algorithms Shortest.pptx
sandeep54552
 
E_R-Diagram (2).pptx
E_R-Diagram (2).pptxE_R-Diagram (2).pptx
E_R-Diagram (2).pptx
sandeep54552
 
Dijkstra Searching Algorithms.pptx
Dijkstra Searching Algorithms.pptxDijkstra Searching Algorithms.pptx
Dijkstra Searching Algorithms.pptx
sandeep54552
 
DFS_New.pptx
DFS_New.pptxDFS_New.pptx
DFS_New.pptx
sandeep54552
 
Agents_AI.ppt
Agents_AI.pptAgents_AI.ppt
Agents_AI.ppt
sandeep54552
 
YCMOU_FYBCA_DS_Unit-7.ppt
YCMOU_FYBCA_DS_Unit-7.pptYCMOU_FYBCA_DS_Unit-7.ppt
YCMOU_FYBCA_DS_Unit-7.ppt
sandeep54552
 
Queue_Data_Structure.pptx
Queue_Data_Structure.pptxQueue_Data_Structure.pptx
Queue_Data_Structure.pptx
sandeep54552
 
Tree_Definition.pptx
Tree_Definition.pptxTree_Definition.pptx
Tree_Definition.pptx
sandeep54552
 
Stack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptxStack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptx
sandeep54552
 
Stack_Data_Structure.pptx
Stack_Data_Structure.pptxStack_Data_Structure.pptx
Stack_Data_Structure.pptx
sandeep54552
 
Heap_Sort1.pptx
Heap_Sort1.pptxHeap_Sort1.pptx
Heap_Sort1.pptx
sandeep54552
 
Quick_sort1.pptx
Quick_sort1.pptxQuick_sort1.pptx
Quick_sort1.pptx
sandeep54552
 
Link_List.pptx
Link_List.pptxLink_List.pptx
Link_List.pptx
sandeep54552
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
sandeep54552
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
sandeep54552
 
Exception handling in c++
Exception handling in c++Exception handling in c++
Exception handling in c++
sandeep54552
 
Inheritance in c++
Inheritance in c++ Inheritance in c++
Inheritance in c++
sandeep54552
 
Constructor and Destructors in C++
Constructor and Destructors in C++Constructor and Destructors in C++
Constructor and Destructors in C++
sandeep54552
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
sandeep54552
 
Jsp tag library
Jsp tag libraryJsp tag library
Jsp tag library
sandeep54552
 

More from sandeep54552 (20)

Dijkstra Searching Algorithms Shortest.pptx
Dijkstra Searching Algorithms Shortest.pptxDijkstra Searching Algorithms Shortest.pptx
Dijkstra Searching Algorithms Shortest.pptx
 
E_R-Diagram (2).pptx
E_R-Diagram (2).pptxE_R-Diagram (2).pptx
E_R-Diagram (2).pptx
 
Dijkstra Searching Algorithms.pptx
Dijkstra Searching Algorithms.pptxDijkstra Searching Algorithms.pptx
Dijkstra Searching Algorithms.pptx
 
DFS_New.pptx
DFS_New.pptxDFS_New.pptx
DFS_New.pptx
 
Agents_AI.ppt
Agents_AI.pptAgents_AI.ppt
Agents_AI.ppt
 
YCMOU_FYBCA_DS_Unit-7.ppt
YCMOU_FYBCA_DS_Unit-7.pptYCMOU_FYBCA_DS_Unit-7.ppt
YCMOU_FYBCA_DS_Unit-7.ppt
 
Queue_Data_Structure.pptx
Queue_Data_Structure.pptxQueue_Data_Structure.pptx
Queue_Data_Structure.pptx
 
Tree_Definition.pptx
Tree_Definition.pptxTree_Definition.pptx
Tree_Definition.pptx
 
Stack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptxStack_Application_Infix_Prefix.pptx
Stack_Application_Infix_Prefix.pptx
 
Stack_Data_Structure.pptx
Stack_Data_Structure.pptxStack_Data_Structure.pptx
Stack_Data_Structure.pptx
 
Heap_Sort1.pptx
Heap_Sort1.pptxHeap_Sort1.pptx
Heap_Sort1.pptx
 
Quick_sort1.pptx
Quick_sort1.pptxQuick_sort1.pptx
Quick_sort1.pptx
 
Link_List.pptx
Link_List.pptxLink_List.pptx
Link_List.pptx
 
Templates in c++
Templates in c++Templates in c++
Templates in c++
 
File handling in c++
File handling in c++File handling in c++
File handling in c++
 
Exception handling in c++
Exception handling in c++Exception handling in c++
Exception handling in c++
 
Inheritance in c++
Inheritance in c++ Inheritance in c++
Inheritance in c++
 
Constructor and Destructors in C++
Constructor and Destructors in C++Constructor and Destructors in C++
Constructor and Destructors in C++
 
C++ programming introduction
C++ programming introductionC++ programming introduction
C++ programming introduction
 
Jsp tag library
Jsp tag libraryJsp tag library
Jsp tag library
 

Recently uploaded

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
IreneSebastianRueco1
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
christianmathematics
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Ashish Kohli
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 

Recently uploaded (20)

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
RPMS TEMPLATE FOR SCHOOL YEAR 2023-2024 FOR TEACHER 1 TO TEACHER 3
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
What is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptxWhat is the purpose of studying mathematics.pptx
What is the purpose of studying mathematics.pptx
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
Aficamten in HCM (SEQUOIA HCM TRIAL 2024)
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 

Enterprise java unit-2_chapter-2

  • 2. Cookies • Hyper Text Transfer Protocol [HTTP] does not maintain a persistent connection. Each request made by a Web browser is made using a new connection. Hence this protocol does not maintain state across HTTP requests, so cookies are used. • Cookies are small text files that are created by a server side program such as a Servlet run at the Web server.
  • 3. Cookies Parameters • cookie has 6 parameters . 1. The name of the cookie 2. The value of the cookie 3. The expiration date of the cookie 4. The path the cookie is valid for 5. The domain the cookie is valid for 6. The need for a secure connection to exist to use the cookie
  • 4. Where cookies are used: • Cookies are most commonly used to track website activity. When you visit some sites, the server gives you a cookie that acts as your identification card • Cookies are also used for online shopping .Online stores often use cookies that record any personal information you enter, as well as any items in your electronic shopping cart, so that you don't need to re-enter this information each time you visit site. • Servers can use cookies to provide personalized web pages. When you select preferences at a site that uses this option, the server places the information in a cookie.
  • 5. 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. After that if request is sent by the user, cookie is added with request by default. Thus, we recognize the user as the old user.
  • 6. Types of Cookies There are two types of cookies:  Permanent / Persistent Cookies  Session / Transient Cookies
  • 7. Permanent / Persistent Cookies Permanent cookies are those cookies that are stored on a user’s computer and are not deleted when the browser is closed. Permanent cookies can retain user preferences for a particular website, allowing those preferences to be used in all future browsing sessions. Permanent cookies can be used to identify individual users, so that the website can analyze the user’s surfing behaviour within the website. Cookies can also be used to provide site information such as the number of visitors, the average time spent on a particular page and generally the performance of the website.
  • 8. Session / Transient Cookies Session or Transient cookies are those cookies that are stored in the computer’s memory only during a user’s browsing session and are automatically deleted from the user’s computer when the Web browser is closed. Those cookies usually store a session ID that is not permanently bound to the user, allowing the user to move from page to page without having to login repeatedly. They are widely used by commercial websites [for example, to keep track of items that a consumer has added to a shopping cart]. Session cookies are never written on the hard drive and they do not collect any information from the user’s computer. Session cookies expire at the end of the user’s browser session.
  • 9. Creating Cookies Using Servlet • Following pages are used for creating cookies 1. index.html 2. FirstServlet.java 3. SecondServlet.java
  • 10. index.html </html> <body> <form action="FirstServlet" method="post" > <input type="text" name="userName"> <input type="submit" value="submit"> </form> </body> </html>
  • 11. FirstServlet.java public class FirstServlet extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { String n=request.getParameter("userName"); out.println("Welcome" +n); Cookie ck=new Cookie("uname", n); response.addCookie(ck); out.print("<form action='SecondServlet' method='post'>"); out.print("<input type='submit' value='submit'>"); out.print("</form>"); } }
  • 12. SecondServlet.java public class SecondServlet extends HttpServlet { protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { Cookie ck[]=request.getCookies(); out.print("Hello" +ck[0].getValue()); out.close(); } }
  • 14. Dynamically Changing the Colors of A Page Following pages are used: • Index.html • DynamicServlet.java
  • 15. Index.html <HTML> <HEAD> <TITLE>Color Change</TITLE> </HEAD> <BODY> <FORM method=get action="DynamicServlet" method="post"> <CENTER> Select Color : <select name="color" id="color"> <option value="red">Red</option> <option value="green">Green</option> <option value="blue">Blue</option> <option value="yellow">yellow</option> <option value="black">Black</option> </Select> <input type="submit" value="Submit"> </FORM> </BODY> </HTML>
  • 16. DynamicServlet.java protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { String c=request.getParameter("color"); if(c.equals("red")) out.println("<body BGCOLOR=red>"); if(c.equals("green")) out.println("<body BGCOLOR=green>"); if(c.equals("green")) out.println("<body BGCOLOR=green>"); if(c.equals("blue")) out.println("<body BGCOLOR=blue>"); if(c.equals("yellow")) out.println("<body BGCOLOR=yellow>"); if(c.equals("black")) out.println("<body BGCOLOR=black>"); out.println("<center><h2>The selected color is:"+c+"</h2></center>");; out.close(); } }