• Post Reply Bookmark Topic Watch Topic
  • New Topic

How did we get to the error page?  RSS feed

 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66144
144
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I can't believe that this question hasn't already been asked/answered somewhere here, but I did a search on "forward error page" and found no helpful results. So here goes:
When the error page defined by a directive such as <%@ page errorPage="/error.jsp" %> is forwarded to as the result of an uncaught exception, is there any way to determine where we came from? A call to request.getRequestURI() merely returns the URI of the error page itself.
I scoured the attributes of all scopes and there's not much helpful there.
I'd really like to be able to find out what URL was being served when the error occurred.
thanks!
bear
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi bear,
this is not an answer to ur q but addition to the confusion
what use one can think of knowing from where the error page resulted? if i want that depending upon the source i want diff error then just have another error page for that source. if we share lot of things b/w two error page put it into some comon file and include it or do sth like that...
so, where do u think, we can use the feature u r talking about?
experts plz comment...
regards
maulin.
 
Gordon Jenkinson
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would something like this work. I've not tried this out but I don't see why it wouldn't work.
<%@ page errorPage="error.jsp?curpage=thispage.jsp" %>

Then you can get the pagename in by getting the parameter from the error page.
 
Madhav Lakkapragada
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have more than one choice....
1. The request object should have a header called "referer" (check the spelling). This should tell you who refered the error page URL.
Tomcat gives an example of how to get the headers. Take a look at that source code.
Personally, I would try this first.
2. In your JSP, throw a Custom Exception something like ExceptionFromMyFirstJSP. In the error page try catching the exception and see
how it maps. Thus you know which JSP in your appln throws this error. This is kinda like the
Exception/Error page support that Tomcat 4.0 supports with the newer Specs.
- satya
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi satya,
ur second option will not work in the following scenario.
if we have common error page for more than one jsp pages (we cant throw just one kind of exception for one jsp). we can get around this by creating one parent class and inheriting children from it and using runtime type detection of the exception type...but thats cumbersome...
i think the first is a good apporach.
Gardon's approach seems better as we don't have to do all kind of referrer grabbing etc and its simple.
regards
maulin.
 
Wendy Frederico
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with Gordon's approach. If you want to get fancy and avoid hard-coding filenames, try sticking this in a separate file.. say errorPath.jsp
<% String path = request.getRequestURI(); %>
<%@ page errorPage="error.jsp?curpage=" + path; %>
then in your jsp pages, all you need is the same include statment.
<%@ include file="errorPath.jsp" %>
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!