Index: /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java
===================================================================
--- /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java	(revision 33255)
+++ /main/trunk/greenstone3/src/java/org/greenstone/gsdl3/LibraryServlet.java	(revision 33256)
@@ -445,5 +445,5 @@
 		session.setMaxInactiveInterval(session_expiration);
 		String uid = session.getId();
-
+		logger.error("uid = "+uid);
 		request.setCharacterEncoding("UTF-8");
 		response.setContentType("text/html;charset=UTF-8");
@@ -464,9 +464,10 @@
 		userContext.setLanguage(lang);
 		userContext.setUserID(uid);
-
+		logger.error ("setting user context "+ uid);
 		if (request.getAuthType() != null)
 		{
 			//Get the username
-			userContext.setUsername(request.getUserPrincipal().getName());
+		  userContext.setUsername(request.getUserPrincipal().getName());
+		  logger.error("adding username "+request.getUserPrincipal().getName());
 
 			//Get the groups for the user
@@ -607,6 +608,6 @@
 		}
 		
-		// logger.info("should_cache= " + should_cache);
-
+		 logger.error("should_cache= " + should_cache);
+		 logger.error("cache key = " + cache_key);
 		//clear the collection-specific cache in the session, since we have no way to know whether this session is 
 		//about the same collection as the last session or not.
@@ -618,4 +619,5 @@
 			{
 				session.removeAttribute(name);
+				logger.error("XXX removing "+name+" from the session");
 			}
 		}
@@ -624,4 +626,5 @@
 		Hashtable<String, Hashtable<String, String>> param_table = null;
 		Hashtable<String, String> table = null;
+		boolean new_table = false;
 		String sid = session.getId();
 		if (should_cache == true && cache_key != null && !cache_key.equals(""))
@@ -629,9 +632,10 @@
 			if (session_ids_table.containsKey(sid))
 			{
+			  logger.error("cache contains sesion id");
 				session_cache = session_ids_table.get(sid);
 				param_table = session_cache.getParamsTable();
 				if (param_table.containsKey(cache_key))
 				{
-					//logger.info("existing table: " + collection);
+					logger.error("existing table: " + cache_key);
 					table = param_table.get(cache_key);
 				}
@@ -640,9 +644,11 @@
 					table = new Hashtable<String, String>();
 					param_table.put(cache_key, table);
-					//logger.info("new table: " + collection);
+					logger.error("new table: " + cache_key);
+					new_table = true;
 				}
 			}
 			else
 			{
+			  logger.error("cache doesn't contain session id");
 				param_table = new Hashtable<String, Hashtable<String, String>>();
 				table = new Hashtable<String, String>();
@@ -651,17 +657,20 @@
 				session_ids_table.put(sid, session_cache);
 				session.setAttribute(GSXML.USER_SESSION_CACHE_ATT, session_cache);
-
-				// here we add in default params?
-				ArrayList<String> defp = this.gs_params.getParamsWithDefaults();
-				Iterator i = this.gs_params.getParamsWithDefaults().iterator();
-				while (i.hasNext()) {
-				    String p = (String)i.next();
-				    String v = this.gs_params.getParamDefault(p);
-				    if (!p.equals(GSParams.ACTION) && !p.equals(GSParams.SUBACTION) && !p.equals(GSParams.LANGUAGE) && !p.equals(GSParams.OUTPUT)) {
-					table.put(p,v);
-				    }
-				}
-				
-			}
+				new_table = true;
+			}
+
+			// here we add in default params if we have a new table
+			ArrayList<String> defp = this.gs_params.getParamsWithDefaults();
+			Iterator i = this.gs_params.getParamsWithDefaults().iterator();
+			while (i.hasNext()) {
+			  String p = (String)i.next();
+			  String v = this.gs_params.getParamDefault(p);
+			  if (!p.equals(GSParams.ACTION) && !p.equals(GSParams.SUBACTION) && !p.equals(GSParams.LANGUAGE) && !p.equals(GSParams.OUTPUT)) {
+			    logger.error("adding to new table default param "+p+", "+v);
+			    table.put(p,v);
+			  }
+			}
+			
+		
 		}
 
@@ -695,4 +704,5 @@
 				{// we have already dealt with these
 
+				  logger.error("query map:" + name);
 					String value = "";
 					String[] values = queryMap.get(name);
@@ -708,8 +718,10 @@
 					if (this.gs_params.shouldSave(name) && table != null)
 					{
+					  logger.error("adding to table");
 						table.put(name, value);
 					}
 					else
 					{
+					  logger.error("adding param to xml param list");
 						Element param = msg_doc.createElement(GSXML.PARAM_ELEM);
 						param.setAttribute(GSXML.NAME_ATT, name);
@@ -731,4 +743,5 @@
 				{
 					String name = keys.nextElement();
+					logger.error("adding from table to session "+name);
 					session.setAttribute(name, table.get(name));
 				}
@@ -737,8 +750,9 @@
 			// put in all the params from the session cache
 			Enumeration params = session.getAttributeNames();
+			logger.error("add in session attributes");
 			while (params.hasMoreElements())
 			{
 				String name = (String) params.nextElement();
-
+				logger.error("session attribute "+name);
 				if (!name.equals(GSXML.USER_SESSION_CACHE_ATT) && !name.equals(GSParams.LANGUAGE) && !name.equals(GSXML.USER_ID_ATT))
 				{
