Pr.Pg Next Pg

JSP program for deleting cookies tutorials

 

JSP program for deleting cookies

Sam Sir

<%--Deletingcookies.jsp--%>

<%--JSP program for deleting cookies--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>JSP Page</title>

</head>

<body>

<center><h3>Deleting Cookies</h3></center>

<%

Cookie cookie = null;

Cookie[] cookies = null;

cookies = request.getCookies();

if( cookies != null ){

out.println("<h2> Cookies Name and Value</h2>");

for (int i = 0; i < cookies.length; i++){

cookie = cookies[i];

if((cookie.getName( )).compareTo("first_name") == 0 ){

cookie.setMaxAge(0);

response.addCookie(cookie);

out.print("Deleted cookie : " +

cookie.getName( ) + "<br/>");

}

out.print("Name : " + cookie.getName( ) + ", ");

out.print("Value: " + cookie.getValue( )+" <br/>");

}

}else{

out.println("<h2>No cookies founds</h2>");

}

%>

</body>

</html>

Output

Deleting cookies

 

 

 

 

 

If there would be no cookies then it will display web page as below:Deleting cookies

Pr.Pg border                                              Next Pg