• Post Reply Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher forward() Goes Into Infinite Loop  RSS feed

 
Vikas Aggarwal
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
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

eg:

http://localhost/app/storyFinder/story213
http://localhost/app/storyFinder/story214
http://localhost/app/storyFinder/story215

in the browser ends up executing the following...

http://localhost/app/jsp/storyFinder.jsp?storyID=213
http://localhost/app/jsp/storyFinder.jsp?storyID=214
http://localhost/app/jsp/storyFinder.jsp?storyID=215

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
accessed.

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
"app"

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

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?
 
Mike Curwen
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:
http://localhost/app/story/story213

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/'
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!