Solved

jsp or javascript - cookies enabled

Posted on 2002-07-30
2
310 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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

726 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