Home Ask Login Register

Developers Planet

Your answer is one click away!

ovod February 2016

jetty with spring MVC session.isNew() returns always false

I am running Jetty 9.3 with Spring MVC and Spring Security. My main page is intercepted by Spring Security Login page which is in JSP. The problem is with my SessionTimeoutIntercepter which should redirect in case of session timeout. What I want to do when the session is timed out - redirect to Spring Security Login page with some parameter like "Session expired". The problem is that session.isNew() which I use always returns false((( I tried with mapping to *"/**"* - the same result. Even after my first request to server and login page - this function returns false((( Can somebody help me why?

Answers


Nikolay Yashchenko February 2016

I think, that some people may do something like

Session session = request.getSession();
if(session.isNew()) {
    //doSmth
}

but method getSession() return new session if it not exists yet. You need getSession(false) - it don't create new session, just return null if it doesn't exists or return old session with timeout expired. In your case, you can add some logic to interceptor

Session session = request.getSession(false);
if(session == null || session.isNew() {
    // do redirect
}

Post Status

Asked in February 2016
Viewed 3,936 times
Voted 10
Answered 1 times

Search




Leave an answer


Quote of the day: live life