I am stuck in quite a tricky problem, That is - My session which contains username is getting invalidating on page refresh in Firefox Mozilla. Same is working fine in IE-9

I am pasting the code of both header and index.jsp file.


Header.jsp

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
<%@ page language="java"
	import="java.util.*,com.project.web.*,com.project.vo.*"
	pageEncoding="ISO-8859-1"%>


<html>
<head>

<script type="text/javascript" src="./js/jquery-1.4.4.js"></script>
	<link href="./css/headerstyle.css" rel="stylesheet" type="text/css"
	media="all" />
	<link href="./css/style_horizontal_naviagation.css" rel="stylesheet" type="text/css" />
	<link rel="stylesheet"
	href="./css/commonheader.css" type="text/css" />
    <script type="text/javascript">
			$(document).ready(function(){
			


var $div1 = $('ul.the_menu');
var height1 = $div1.height();
$div1.hide().css({ height : 0 });

$("img#menu_class").click(function () {
  if ( $div1.is(':visible') ) {
	  $("ul.the_menu").slideUp(800);
	                        setTimeout(
							function() {
							    $('ul.the_menu').stop(true, true).hide(); 
							}, 700);
  } else {
	$div1.css({ height: 20});
    $div1.show().animate({ height : 300 }, { duration: 800 }, {"easing": "easein"});
  }
    
  return false;
});






var $div = $('#contactForm');
var height = $div.height();
$div.hide().css({ height : 0 });

$("#contactLink").click(function () {
  if ( $div.is(':visible') ) {
	  $("#contactForm").slideUp(800);
                        setTimeout(function() {
						    $('#contactForm').stop(true, true).hide(); 
						}, 700);
  } else {
	$div.css({ height: 20});
    $div.show().animate({ height : 300 }, { duration: 800 }, {"easing": "easein"});
  }
    
  return false;
});




			//demo 1
					
                
			//demo 2
			//$('select#valueA, select#valueB').selectToUISlider();
			
		
			//demo 3

		
		});
		//purely for theme-switching demo... ignore this unless you're using a theme switcher
		//quick function for tooltip color match
	
		
	</script>
    

</head>
<body>


<%!String username;%>
 <% username = (String) session.getAttribute("username");

session.setAttribute("username", username);
 %>
<div id="header" >

<div id="horizontalnav1">
		<a href="../udaan/"><img src="images/home.png" width="87" height="49" alt="Home" /></a>
		</div>
	<div id="horizontalnav2">	
	<div id="container_menu">
<div id="button">
<img src="images/categories.png" width="130" height="48" alt="Categories" id="menu_class" /><ul class="the_menu">
<li><a href="#">A Website #1</a></li><!--
--><li><a href="#">A Website #2</a></li><!--
--><li><a href="#">A Link #1</a></li><!--
--><li><a href="#">A Link #2</a></li><!--
--><li><a href="#">A Website #3</a></li><!--
--><li><a href="#">A Website #4</a></li><!--
--><li><a href="#">A Link #3</a></li><!--
--><li><a href="#">A Link #4</a></li>
</ul>
</div>

</div>

	
</div>
<div id="horizontalnav3">
					<a href="./postAdRedirect.jsp?username=<%=username%>"><img src="images/postad.png" width="102" height="49" alt="Post Ad" /></a>

</div>
<div id="horizontalnav4">
					<a href="./myDetailsRedirect.jsp"><img src="images/myvfinds.png" width="124" height="49" alt="MyVfinds" /></a>

</div>

<% 
		if ((username == null) || (username == "")) {
%>
<div class="box">
<div id="contactFormContainer">
<div id="contactForm">
<form id="loginform" action="login.do" method="post">
<fieldset><label for="username">Username *</label> <input
	name="username" type="text" /> <label for="password">Password
*</label> <input name="password" type="password" /> <input id="submit"
	type="submit" name="submit" onclick="submitform()" /> <span
	id="messageSent">Your message has been sent successfully!</span></fieldset>
</form>
</div>
<div id="contactLink"></div>
</div>
</div>

<%
	} else {
%>

<div id="logout">
<a href="logout.do"><img border="0"
	width="100%" height="100%" alt="" src="images/logout.gif"></a>
	<form id="#">

</form></div>
<%
	}
%>



</div>
</body>
</html>

Index.jsp

<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
 <!DOCTYPE taglib
    PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
    "http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">

<%@ page language="java"
	import="java.util.*,com.project.web.*,com.project.vo.*"
	pageEncoding="ISO-8859-1"%>

<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<%
String cookieName = "city";
Cookie cookies [] = request.getCookies ();
Cookie myCookie = null;
if (cookies != null)
{
for (int i = 0; i < cookies.length; i++) 
{
if (cookies [i].getName().equals (cookieName))
{
myCookie = cookies[i];
break;
}
}
}
%>
<html>
<head>
<style type="text/css">@import url("thickbox.css") screen;</style>
<title>VFinds...</title>

<meta name="Description" content="How to Build a Basic CSS Layout" />
<meta name="Keywords" content="css layout" />
<link rel="stylesheet"
	href="./css/homepage.css" type="text/css" />
	

<link href="./css/showhide.css" rel="stylesheet" type="text/css"
	media="all" />
	<script type="text/javascript" src="./js/cookie.js"></script>
	


			        <link href="homepageslider.css" rel="stylesheet" type="text/css" media="all" />
	    <script src="jquery-1.2.6.js" type="text/javascript" charset="utf-8"></script>
    <script src="jquery-ui-full-1.5.2.min.js" type="text/javascript" charset="utf-8"></script>

<script type="text/JavaScript" src="./js/curvycorners.src.js"></script>

<link rel="stylesheet" href="general.css" type="text/css" media="screen" />
	<script src="popup.js" type="text/javascript"></script>

<link rel="stylesheet" type="text/css" href="./css/style.css" />

<script type= "text/javascript" src="subCategoryClassfiedAjaxHomepage.js"></script>
<script type="text/javascript" src="./js/combo.js"></script>

<script type="text/javascript">
function submitform()
{
  document.loginform.submit();
  closeForm();
}
function submitformSearch()
{
  document.search.submit();
  closeForm();
}


</script>

<script src="thickbox.js" type="text/javascript"></script>
    <script type="text/javascript" charset="utf-8">
	       
        window.onload = function () {
checkCookieForCity();
           
 };
    </script>

    
    
 
<script type="text/javascript">
<!--
    function toggle_visibility(id) {
       var e = document.getElementById(id);
       if(e.style.display == 'block')
          e.style.display = 'none';
       else
          e.style.display = 'block';
    }
//-->
</script>

<style type="text/css">
fieldset {
	border: 0;
	margin: 5px;
	height: 8em;
	width: 190px;
}

label {
	font-weight: normal;
	margin-right: .5em;
	font-size: 12px;
	color: #5A5A5A;
}

select {
	margin-right: 1em;
}

.ui-slider {
	clear: both;
	top: 1em;
}
</style>


<!-- jQuery UI theme switcher -->

<script type="text/javascript">
function submitform()
{
  document.loginform.submit();
  closeForm();
}
</script>




</head>
<body>
<%!String[] destList;%>

<div id="wrapper">
<%@include file="./header.jsp"%>

<%! public static String cityvalue = null;
public static String city = null;%> 

<%
if (myCookie == null) {
%>
No Cookie found with the name <%=cookieName%>
<%
} else {
%> 

<%
session.setAttribute("city",myCookie.getValue());

 city = (String)session.getAttribute("city");
 
	int citylength = city.length();
	String remainingletterexceptfirst = city.substring(1, citylength);
	String cityfirstletter = city.substring(0,1);
	String newcityfirstletter = cityfirstletter.toUpperCase();
	 cityvalue = newcityfirstletter + remainingletterexceptfirst;
	%>
	City from session = <%=cityvalue%>
Welcome: <%=cityvalue%>.
<%
}
%>

<div id = "username" style="position: absolute; left: 20px; top: 71px; width: 118px; z-index: 0;">

<%

if(username == null){
		out.println("You are not logged in");

%><b></b><%
}else{
	out.println("Welcome : " + username );
	}%>
</div>


<div id="modifysearch">
	<div class="myBox">
	
	<form id = "search" action="search.do">
	<div id = "text" style="position:relative;left:15px;top:15px;width:153px; height:40px;" >
	
	<font color="#463E3F"><B><I>Interested in </I></B></font>
	
	</div>
<div id = "category" style="position:absolute;left:110px;top:15px;width:153px;">
<select name="category" id = "category_id"  onchange="showSubcategoryClassfiedHomepage(this.value)"  >
<option >--Select category--</option>
<option value = "realestate">Real Estate</option>
<option value= "appliances" >Appliances</option>
<option value =  "households">House Holds</option>
<option value = "vehicle">Vehicles</option>
<option value = "computers">computers and Mobiles</option>
  </select>
  </div>

   <div id="subcategory" style="position:absolute;left:290px;top:15px;width:153px;">
<select name="subcategory"   id="subcategory" class="combo">
<option value="">-- Select Sub Category--</option>
</select>
</div>

   <div id="city" style="position:absolute;left:470px;top:15px;width:153px;">
<select name="city" >
<option selected value=<%=cityvalue%>><%=cityvalue%></option>
<option value = "bangalore">Bangalore</option>
  <option value= "delhi" >Delhi</option>
  <option value =  "mumbai">Mumbai</option>
</select>
</div>
   <div id="submit" style="position:absolute;left:590px;top:4px;">
 <input id="submit" type="Submit" name="submit" onclick="submitformSearch()" />
</div>
</form>



    </div>





</div>

<div id="footer">footer</div>

</div>

<div id="popupContact">
		<a id="popupContactClose">x</a>
		<h1>Choose City</h1>
		<p id="contactArea">
		Bangalore : <input type="radio" name="formradio1" value = "bangalore" onClick="javascript: setCookie('city','bangalore',365);" >
			<br/><br/>
		Delhi : <input type="radio" name="formradio1" value = "delhi"  onClick="javascript: setCookie('city','delhi',365);" >
			<br/><br/>
			<a target="_parent" href= "../udaan/index.jsp" > Click here to continue...<img src=" "></a> 

		</p>
	</div>
	<div id="backgroundPopup"></div>
</body>
</html>

I am not sure why its happening only in Mozilla.Thanks in advance.

For quick understanding i am copying the code which may has a problem

Below is the code snipet from header.jsp, Which i am including in index.jsp

<%!String username;%>
<% username = (String) session.getAttribute("username");

session.setAttribute("username", username);
%>

On page refresh session is getting invalidating in Firefox mozilla. Working fine in IE

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.