This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Finding current URI?  RSS feed

Rick Beaver
Ranch Hand
Posts: 464
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am trying to find out the current URI loaded from a header that is included in all JSP files.

using request.getRequestURI() I can get the URI fine, until I do a forward / redirect.

The basis of what I am trying to do is to test if the current page is a.jsp and if so, dont redirect to a.jsp, if it is anything else, redirect to a.jsp.

The problem of course is that as the request.getRequestURI() does not change when you use <jsp:forward> or response.sendRedirect() I end up in an infinite loop of forwarding to a.jsp.

Has anyone an idea how to find the fact that I am at a.jsp without passing any parameters in the request?


If I have this in b.jsp:

The getRequestURI() is always b.jsp in this test so it keeps redirecting to a.jsp, which breaks the app.
Michal Bienek
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By having this code in b.jsp, you will never have a requestURI of a.jsp.
By doing a jsp:forward, you are internally changing the location, but the request URI will not change. The browser requested b.jsp and nothing else. Therefore, b.jsp will never be referenced by a requestURI of a.jsp.
I must be missing something in your problem statement.

here's the flow:
browser (request b.jsp) -> webserver -> b.jsp (forwards to) -> a.jsp

say b.jsp told the browser to redirect to a.jsp, then the flow would be:
browser (request b.jsp) -> webserver -> b.jsp (redirect to a.jsp) -> browser (now request a.jsp) -> webserver -> a.jsp

In no way can a webserver, when getting a request for a.jsp, would respond to the request with b.jsp (unless you are aliasing a.jsp to point to b.jsp, but based on your problem statement, that doesn't seem to be the case)
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!