jsp or javascript - cookies enabled

I was using the followign script - and all is good except
that is was discovered that when a person first opens there browser and if they first go to the page with this code, they will be forwarded to the disable cookies page even if there cookies are not disable, a refresh will solve the problem, but is there another way???

<%-- if cookies are disabled - will forward to enable cookies page--%>
   String cookies = request.getHeader("Cookie");
   boolean  cookiesEnabled = true;
   if (cookies == null) {
   cookiesEnabled = false;
   <jsp:forward page="enable-cookies-e.jsp"/>
   } else {
  <%-- cookies are fine - stay here--%>
<% } %>
Who is Participating?
OMC2000Connect With a Mentor Commented:
There are two possible solutions: server and client based.
CJ S mentioned Server side solution.
Since there is no relaible way to check whether cookies enabled or not in general from server side
You may make the first page that
- attempts to set your application cookies and
- contains only Javascript code that loads another page that will check your application cookies;
<script language="javascript">

checkCookies.jsp will look like your code above with only exception. You should check your application cookies, not general ones.

client side solution based on DHTML
<script language="javascript">
var bEnabled = navigator.cookieEnabled;
if ( bEnabled ) {
} else {

Write a cookie first then read the cookie. Don't know the JSP code.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.