Forums Register Login

How to cleare the cookies stored in a Cookie class in JSP file?

+Pie Number of slices to send: Send
Hiii all,

I am developing some distributed application where I will add some values to Cookies using response object in one JSP page. The same thing I want to retrive in another JSP page using request object(this is the page which I wil get after pressing button in my first JSP page). When I first wrote and checked it was working fine but when I closed the application and open it again it is retriveing some arbitory values. It is difficult to give all part of code since it very big hence some portion of code is given below. Can anybody tell me how to cleare the values stored in Cookies on exit....? Please help... suggestions are welcome....

first JSP page:
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<%
int y=1;
String sever=request.getParameter("treat");
String st_date=request.getParameter("start");
String nd_date=request.getParameter("end");
String stas=request.getParameter("all");
String [] str=request.getParameterValues("allergies");
int counter=str.length;
for(int i=0; i <str.length; ++i)
{
String immunu="immunity";
immunu+=y;
++y;
Cookie ck=new Cookie(immunu,str[i]);
ck.setMaxAge(60*60*24);
response.addCookie(ck);
}
for(int i=0; i <str.length; ++i)
{

if(sever!=null && st_date!=null && nd_date!=null && stas!=null)
{
%> <tr><td valign="top"><%=str[i]%></td>
<td valign="top"><%=sever%></td>
<td valign="top"><%=st_date%></td>
<td valign="top"><%=nd_date%></td>
<td valign="top">---</td>
<td valign="top">---</td>
<td valign="top"><%=stas%></td>
<td><a href="addrecord.jsp">Add record</a><br />
<a href="editrecord.jsp">Edit</a><br />
<a href="delrecord.jsp">Delete</a><br />
</td>
</tr>
<%
}
else
{
%>
<tr><td valign="top"><%=str[i]%></td>
<td valign="top">---</td>
<td valign="top">---</td>
<td valign="top">---</td>
<td valign="top">---</td>
<td valign="top">---</td>
<td valign="top">---</td>
<td><a href="addrecord.jsp">Add record</a><br />
<a href="editrecord.jsp">Edit</a><br />
<a href="delrecord.jsp">Delete</a><br />
</td>
</tr>

<% }
}
Integer num=new Integer(counter);
String str_counter=Integer.toString(num);
session.setAttribute("COUNTER",str_counter);
%>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
second JSP page:
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
<%
int y=2;
String immunu="immunity1";
int adder_counter=Integer.parseInt((String)session.getAttribute("COUNTER"));
Cookie [] ck=request.getCookies();
if (ck != null)
{
for (int i=0;i<adder_counter;++i)
{

if(ck[i].getName().equals(immunu))
{
immunu="immunity";
immunu+=y;
++y;
String immunization=(String)ck[i].getValue();
%> <input type=HIDDEN name="allergies" value="<%=immunization%>">
<% }
}
}

%>
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Regards,
Abhjit
+Pie Number of slices to send: Send
First, move all that code out of the JSP and into Java classes. It's 2010, not 2002.

Secondly, please UseCodeTags.
Is this the real life? Is this just fantasy? Is this a tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1273 times.
Similar Threads
Doubts in jsp
Error comes whilke compiling the jsp page
To call and load javascript in struts jsp.
how to preserve the lastly added contents in table in JSP page?
Shoppingcart session problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:57:41.