?
Solved

jsp or javascript - cookies enabled

Posted on 2002-07-30
2
Medium Priority
?
316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 800 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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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…
Suggested Courses

770 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