code: protected UnitBean getCurrentUnit(HttpServletRequest req, boolean saveToSession){
  		String unitParameter = req.getParameter(PARAM_UNIT);
  		if (unitParameter==null){
  			UnitBean ret = (UnitBean)req.getSession().getAttribute(BEAN_UNIT);
  			if (ret==null){
  				ret = DEFAULT_UNIT_BEAN;
  				//ensure a unit bean is always in the session.
  				req.getSession().setAttribute(BEAN_UNIT, ret);
  			}
  			return ret;
  		}
  
  		int index = -1;
  		for (int i = 0; i<AVAILABLE_UNITS_LIST.size(); i++){
  			if (AVAILABLE_UNITS_LIST.get(i).getUnitName().equalsIgnoreCase(unitParameter)){
  				index = i;
  				break;
  			}
  		}
  		UnitBean ret = index == -1 ? DEFAULT_UNIT_BEAN : AVAILABLE_UNITS[index];
  		if (saveToSession)
  			req.getSession().setAttribute(BEAN_UNIT, ret);
  		return ret;
  	}
docs: Returns the currently selected unit either from request or session.
  @param req
  @param saveToSession - if true the request parameter  will be saved into session.
  @return