How can i maintain last cookie value in flex with jsp?
Posted
by praveen
on Stack Overflow
See other posts from Stack Overflow
or by praveen
Published on 2010-05-31T13:02:29Z
Indexed on
2010/05/31
14:23 UTC
Read the original article
Hit count: 229
Hi All, my login form in flex when I login I have created a cookie in jsp like this name setValueCookie.jsp
<%@ page language="java" import="java.util.* , javax.net.*" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<%
String username = request.getParameter("value");
System.out.println("Email got in cookieSet = " + username);
if(username==null) username="";
Date now = new Date();
String timestamp = now.toString();
Cookie cookie = new Cookie("username",username);
cookie.setMaxAge(365 * 24 * 60 * 60);
response.addCookie(cookie);
%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>DashBoard-Cookie</title>
</head>
<body>
</body>
</html>
now using Http service request parameter i am passing username 'Value' to this jsp. and i am reading cookie value from getValueCookie.jsp like this
<%
String cookieName = "username";
Cookie cookies [] = request.getCookies ();
Cookie myCookie = null;
String result;
if (cookies != null)
{
for (int i = 0; i < cookies.length; i++)
{
if (cookies [i].getName().equals (cookieName))
{
myCookie = cookies[i];
break;
}
}
}
%>
<data>
<status><%=myCookie.getValue().toString()%></status>
</data>
through the httpservice value i am getting but if i open a new window or any new tab cookie value is not getting how can i solve this? Thanks in advance.
© Stack Overflow or respective owner