You can test it:
1. establish a cookie:
Date dtoday = new Date();
String stoday = dtoday.toString();
Cookie lastVisit = new Cookie("lastVisit", todayString);
response.addCookie(lastVisit);
2. access the cookie:
Cookies[] myCookies = request.getCookies();
for (int i=0; i<myCookies.length; i++) {
out.println("Cookie name:" + myCookies[ i ].getName());
...
}
You get your Cookie, if the browser supports cookies!
Andreas Spall>
No you shouldnt
try:
YourJSP.jsp
********
Begin
********
<%@ page language="java" contentType ="text/html" %>
<%@ page import="java.util.*" %>
<%
StringsIsFirstRun= request.getParameter("questionedpos");
booleanbresult = false;
if (sIsFirstRun == null) {
Date dtoday = new Date();
String stoday = dtoday.toString();
Cookie lastVisit = new Cookie("lastVisit", todayString);
response.addCookie(lastVisit);
//sIsFirstRun = "NoIsNot";
%>
<meta http-equiv="refresh" content="0; URL=orderprocess.jsp?sIsFirstRun=NoIsNot">
<%
} // eo if(sIsFirstRun..
else {
Cookies[] myCookies = request.getCookies();
for (int i=0; i<myCookies.length; i++) {
String sName = "" + myCookies[ i ].getName());
if(sName.equals("lastVisit")
bresult = true;
} // eo for(int...
} // eo else
if (bresult == true) {
// *****************************
// Your jsp
// *****************************
}
********
End
********
Info:
<meta http-equiv="refresh" content="0; URL=orderprocess.jsp?sIsFirstRun=NoIsNot">
This can be critical
Andreas Spall
hi,
checking whether your browser supports cookies or not is fine.
but ultimately you want to maintain sessions. the best way for this is to use the concept of URLRewriting in which your web server itself checks ip your browser compatibility and accordingly either wirtes cookies to the browser if it supports or will append it to the url if it doesn't. this solves all the headaches about cookies and the security breach.
regards
srini