You can save the current page to the session in each page, for every page but the login page. Then after login redirect to the value of the current page parameter from the session if one exists, and to the index if it doesn't.
In each page:
session.setAttribute("currentpage", pagename);
In the login code:
String pagename = (String)session.getAttribute("currentpage");
if(pagename == null)
{
pagename = "index.jsp";
}
response.sendRedirect(pagename);