• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First, move all that code out of the JSP and into Java classes. It's 2010, not 2002.

Secondly, please UseCodeTags.
reply
    Bookmark Topic Watch Topic
  • New Topic