Win a copy of Java EE 8 High Performance this week in the Java/Jakarta EE forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher forward() Goes Into Infinite Loop  RSS feed

Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw this problem of somebody and myself getting this.
I'm trying to configure tomcat and my code to create urls which look static,
but behave dynamically



in the browser ends up executing the following...


To this end I created a servlet called "Mapper", the sole role of which is
to forward requests to a JSP when an url matching "/storyFinder/*" is

In "Mapper's" doGet/doPost methods I do the following

String storyId = request.getPathInfo();
RequestDispatcher d =
request.getRequestDispatcher("/jsp/storyFinder.jsp?storyId=" + );
d.forward(request, response);

In my web.xml I inserted the following into the definition of the web-app

<servlet-mapping url-regexp='/storyFinder/*' servlet-name='Mapper' />
<servlet servlet-name='Mapper' servlet-class='Mapper'>
<load-on-startup />

However something odd occurs when a request is made. A Servlet Exception
"too many servlet includes" occurs, as an apparent infinite loop is created
by this configuration.

Any ideas on how to fix this?
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not an expert at regex, but I think I know what *could* be happening.

Your pattern to match is '/storyFinder/*' and you forward to storyFinder.jsp. Might this match that pattern? I think you have to escape the forward slashes, don't they mean something in regex?

Otherwise, you can do this:

Try changing your original URL requests to:

And then map 'story\/*' to your servlet. When you then try to forward or include storyFinder.jsp there is no possible way it can loop on this, because 'storyFinder' doesn't match 'story/'
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!