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

[2706 byte] By [lnthai2002a] at [2007-11-27 7:56:40]
# 1

You simply can not map a servlet to the '/" pattren because then every request goes to the servlet even when it comes from a RequestDispatcher. One solution would be to map the front controller servlet to any url with an extension like ".do". The other servlets would be mapped to the same url but with out the ".do" extension. The front controller can then do it's processing and then dispatch to the next servlet based on parsing the request url.

tolmanka at 2007-7-12 19:38:18 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...