Pr.Pg Next Pg

JSP program for reading cookies tutorials

 

JSP program for reading cookies

Sam Sir

<%--Readingcookies.jsp--%>

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

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

<html>

<head>

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

<title>Cookies Reading</title>

</head>

<body>

<center><h3>Reading Cookies</h3> </center>

<%

Cookie cookie = null;

Cookie[] cookies = null;

cookies = request.getCookies();

 

if( cookies != null ){

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

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

cookie = cookies[i];

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

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

}

}else{

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

}

%>

</body>

</html>

Output

Reading cookies

Pr.Pg border                                              Next Pg