Solved

jsp or javascript - cookies enabled

Posted on 2002-07-30
2
309 Views
Last Modified: 2008-02-01
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--%>
<% } %>
0
Comment
Question by:schroom
2 Comments
 
LVL 22

Expert Comment

by:CJ_S
ID: 7188165
Write a cookie first then read the cookie. Don't know the JSP code.

CJ
0
 
LVL 15

Accepted Solution

by:
OMC2000 earned 200 total points
ID: 7188261
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">
     window.navigate("checkCookies.jsp");
</script>

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 ) {
window.navigate("good-luck-you-are-able-to-work.jsp");
} else {
window.navigate("enable-cookies-e.jsp");
}
</script>




0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question