Prior to hitting the index2.jsp page I have created a session in a servlet and set the MaxInterval value to 15(seconds) using the inbuilt setMaxInterval... function. Thereafter I use a sendRedirect to get to index.jsp page.
The index.jsp that contains a link pointing to index2.jsp. When I click it after 15seconds my response.sendRedirect("/sessionExpired.jsp") doesn't go to sessionExpired.jsp but prints only OSR(content of index2.jsp) on the index2.jsp page.
I don't want it to go to index2.jsp page if the session becomes invalid. I want it to redirect to sessionExpired.jsp instead. How should I do this?
It might be something to do with the way that <jsp:include> works, I don't know. But I would never have done it that way in the first place, so I don't really care either. You should really make the decision about whether to redirect or not before you run any JSPs at all. Especially if the question is "Is the session timed out?" -- that sort of thing should be in a servlet filter.
The problem was with the jsp:include! Instead of using that I used the include directive. Apparently the former returns the result of the resultant servlet and embeds it in the index2.jsp file. However, include directive works differently.
However, as paul pointed out I am going to keep the session Management code in a servlet which results to a better design.