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
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