ininite loop in front controller
Hi,
I have a servlet mapped to /,/* in the web.xml which responsible for directing all request to coresponding resources as follow:
protectedvoid processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String id = request.getRequestURI();
id = id.substring(request.getContextPath().length());
String dest;//destination
// If no request is received or if the request received is
// for the root, serve /WEB-INF/docs/index.jsp
if (id ==null || id.trim().equals("") || id.equals("/"))
dest ="/WEB-INF/docs/index.jsp";
elseif(id.equalsIgnoreCase("/financial"))
dest ="/Financial";//financial servlet
elseif(id.equalsIgnoreCase("/authentication"))
dest ="/Authentication";//authentication servlet
else
dest = id;
//SEND TO DESTINATION
try
{
request.getRequestDispatcher(dest).forward(request, response);
}
catch(Throwable t)
{
getServletContext().log(t.getMessage());
}
}
When there is a request for /, there is an infinite loop to forward the request to /WEB-INF/docs/index.jsp because request.getRequestDispatcher(request).forward(request,response) is not forwarding the request to index.jsp but to the front controller servlet itself again. Is there anyway i ca solve this problem?
I saw the front controller design pattern example from sun and in that example, they use the requestDispacher from the servlet context, not from the request like i did. Is there any different between these 2?
http://java.sun.com/blueprints/corej2eepatterns/Patterns/FrontController.html
Hope to get some hint
Message was edited by:
lnthai2002

