You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by ro...@zzict.nl on 2000/12/02 22:09:28 UTC
servlet delegation problem.(stupid me can't get 15 lines of code
right)
Yo
dudes,
it's late, and I have been looking at this for too long now:
The idea was simple:
store all JSP pages that need authentication in a NEEDSAUTHENTICATION
subdirectory and put a servlet in front of it that checks wether
the session was authenticated, and delegate to a logon page if not,
and delegate to the normal JSP handler if it was.
In theory this is 15 lines of code maximum.
But I can't get It to work:
If or the request get's delegated to this servlet again, by the
Dispatcher, or the servlet engine goes and looks for the pages in
the wrong directory (forward eats a part of the path.)
The servlet
looks like this:
public class BasicAuthenticationServlet extends HttpServlet {
public void doGet (HttpServletRequest request,
HttpServletResponse response) {
try {
HttpSession session=request.getSession();
String isAuthenticated= (String)
session.getAttribute("isAuthenticated
");
if(!"true".equals(isAuthenticated)){
getServletConfig().getServletContext().getRequestDispatcher("/logon.jsp").forward(request, response);
}else{
String uri=request.getRequestURI();
RequestDispatcher dispatcher=
getServletConfig().getServletContext().getNamedDispatcher("jsp")
;
dispatcher.include(request, response);
}
} catch (Exception ex) {
ex.printStackTrace ();
}
}
}
Help is appreciated.
Sloot.