Brian,
If I understand you correctly, here is what you want to do:
1) You encounter a page that requires user authentication, so your code checks the session to see if the user has authenticated...
Boolean loggedIn = (Boolean)session.getAttribute("loggedIn");
The user has not logged in, so your page stores its URL in the session...
session.setAttribute("page", "my_page.jsp");
...and forwards the request to the login page.
requestDispatcher.forward(req, res);
2) Now the login page receives a request so it displays a login form. The end user submits his login info; it is posted to the LoginServlet.
3) LoginServlet receives the login info and matches it against a database of username and passwords. The user has now authenticated successfully, so the LoginServlet wants to return him to the page he originally requested (my_page.jsp). So, LoginServlet accesses the session...
String redirect = (String)session.getAttribute("page");
...and redirects the end user to that page.
rd = getServletContext().getRequestDispatcher(redirect);
rd.forward(req,res);
4) Now the user is back at the page he started on and this time he is allowed to view the page because he has successfully logged in
Hope that helps!
Mensa member, Certified bartender, Created the Internet (along with Al Gore), Speak 9 languages fluently (this includes pig latin), Spelling Bee Winner, 8th Grade Math Award, Can hold breath under water for more than 2 minutes