That is a good question....
I can think of two ways:
1) Set up your browser to deny cookies and then upload to a servlet that calls addCookie() . See if an Exception is thrown and, if so, just key off that Exception- in other words, catch that Exception and forward them to a page that explains they need to enable cookies. I'm not sure if this approach would work since addCookie() throws no Exceptions- but I suppose that it will depend upon how it is implemented in your server.
2) write a javascript or java routine that adds a cookie and then checks to see if the cookie is immediately present. You can forward the user to the proper page based upon its availablity. That routine might be process-intensive for every page, but hopefully you would only need to complete it once, at login- same with suggestion number one.... ...take care. If you find easier solutions, please post it.
What do u think about this method
I think this is the most easy to deploy
public class myServlet extends
HttpServlet {
public void doGet(request HttpServletRequest, response HttpServletResponse) {
String result = request.getParameter("testcookie");
if (result!=null) {
if ("true".equalsIgnoreCase(result)) {
Cookie C2 = request.getCookie();
if (C2==null) {
System.out.println("cookies not allowed");
} else {
System.out.println("cookies allowed");
}
}
} else {
Cookie C = new Cookie();
C.setValue("essai de cookie");
response.addCookie(C);
response.sendRedirect("/myservlet?testcookie=true");
}
}
}