Results 1 to 1 of 1
Thread: Reading cookies in JSP
-
Reading cookies in JSP
Code below reads cookie and displays the contents on the browser.
Java Code:<%@ page language="java" %> <% String cookieName = "username"; Cookie cookies [] = request.getCookies (); Cookie myCookie = null; if (cookies != null) { for (int i = 0; i < cookies.length; i++) { if (cookies [i].getName().equals (cookieName)) { myCookie = cookies[i]; break; } } } %> <html> <head> <title>Show Saved Cookie</title> </head> <body> <% if (myCookie == null) { %> No Cookie found with the name <%=cookieName%> <% } else { %> <p>Welcome: <%=myCookie.getValue()%>. <% } %> </body>
Similar Threads
-
Getting all the cookies from Servlet
By Java Tip in forum Java TipReplies: 0Last Post: 01-25-2008, 07:13 PM -
JSP cookies example
By Java Tip in forum Java TipReplies: 0Last Post: 01-15-2008, 03:11 PM -
Reading cookies from JSP
By Java Tip in forum Java TipReplies: 0Last Post: 12-10-2007, 05:37 PM -
Setting cookies in JSP
By Java Tip in forum Java TipReplies: 0Last Post: 12-10-2007, 05:33 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks