Posted By:
Adi2000_Sharma
Posted On:
Friday, June 25, 2004 09:00 AM
Hi, I am using Windows 2000 Server.Software -JDK1.3 and J2EE 1.2.Problem is that cookies whose maximum age signifies persistent are not stored on my machine. I checked using Search by windows also. At the same time i get misleading results on use of cookies. I have used 'Prompt' also on cookies properties.Still its same despite all properties correct.If this code exemplifies the problem kindly let me know what to do :- Here's the code import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; import java.sql.*; public class Cookieadd extends HttpServle
More>>
Hi,
I am using Windows 2000 Server.Software -JDK1.3 and
J2EE 1.2.Problem is that cookies whose maximum age
signifies persistent are not stored on my machine.
I checked using Search by windows also.
At the same time i get misleading results on use of cookies.
I have used 'Prompt' also on cookies properties.Still its
same despite all properties correct.If this code exemplifies
the problem kindly let me know what to do :-
Here's the code
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
public class Cookieadd extends HttpServlet
{
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException,IOException
{
Connection con=null;
int ctr=0;
boolean cookieFound=false;
Cookie c=null;
String com=new String (" ");
String rt=new String(" ");
String st1="B00";
PrintWriter pw=res.getWriter();
Cookie[] cookieset =req.getCookies();
pw.println(cookieset.length);
for (int i=0;i
{
if (cookieset[i].getName() !=null) {
pw.println(cookieset[i].getName());
}
if (cookieset[i].getName().equals("Booksjargon"))
{
cookieFound=true;
c=cookieset[i];
}
}
if (cookieFound==true) {
pw.println("Hi ! user");
}
if (cookieFound==false) {
pw.println("Welcome to your first shopping");
}
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:MyData","","");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from books_for_sale");
ctr=0;
while (rs.next()) {
com=st1+Integer.toString(ctr);
rt=req.getParameter(com);
if ((rt !=null) && (cookieFound==true)) {
res.setContentType("text/html");
c.setValue(com);
c.setMaxAge(3600*24*30);
res.addCookie(c);
}
else if ((cookieFound==false) && (rt !=null))
{
c = new Cookie("Booksjargon",com);
c.setMaxAge(3600*24*30);
res.addCookie(c);
pw.println("A Cookie was added to your system");
}
ctr=ctr+1;
}
}
catch(Exception d)
{
pw.println("Cannot display the record" +d);
}
}
}
<<Less