• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

How did we get to the error page?

 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 5040
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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" %>
 
We've gotta get close enough to that helmet to pull the choke on it's engine and flood his mind! Or, we could just read this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic