I want to know how can I redirect to a jsp Page whe session of the page expires. I use Resin 2.1.5.

Christopher Koenigsberg

if(request.isRequestedSessionIdValid())

Ah, I didn't know about this method! I didn't think of looking in the request object for this info, I had only thought of the session object itself.... Instead in my "checksession.jsp" I had been trying to do something with the session (getId()), and then catching the exception if it is invalid. I will try this instead!

Here's what I had/have instead. My checksession.jsp, included at the top of all my jsp's, uses a utility class which has the following method, taking an HttpSession argument, and telling if it is currently valid or not, by doing a getId() and then catching the IllegalStateException if thrown (meaning the session is invalid).

Another thing about this code, I had thought that session.isNew() would never happen by the time this method was called on it, but in practice I found that isNew() was occurring most of the time, more often than not..... hence the warning "this should never happen" had to be commented out, so it wouldn't fill up our Log4j log files!!

######################################

	public static boolean isSessionStillValid(HttpSession insession) {
		if (null == insession) {
//			logger.warn(" Session is null!");
			return false;
		}

 // An invalidated session will throw an IllegalStateException, that's the only way to tell (?)
 // because there is no "isValid()" test method on an HttpSession.
		try {
			if (insession.isNew()) {
// session isNew until we complete a successful login, so should never be true as long
// as we call this AFTER successful login (not on index/login page!) but just in case,
// return true instead of false so the session can continue with just our warning in
// the log.
				logger.warn(" Session is still "new"! (should never happen?)");
			}
			String thesessionid = insession.getId();
			if (null == thesessionid) {
				logger.warn(" Got null SessionID from Session.getID?");
			} else {
//				logger.debug(" Valid session, ID = " + thesessionid);
			}
			return true;
		} catch (IllegalStateException exc) {
			logger.warn(" Session is invalid!");
			return false;
		}

	} // end isSessionStillValid()


0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact