• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

forwarding not quite working

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm working on a servlet. In several places, if an error condition is detected, I want to forward to an jsp page to display information about the error. The problem is that this error condition may be buried way down the call stack, and after forwarding, the servlet continues to execute code.

Here is the code of a trivial servlet that illustrates the problem.




When I run this, it forwards just fine to the jsp page but it prints out the line saying "You should never see this". If I uncomment the "if (true) return;", the code works as expected; however, I may want to call fail() from way down the call stack and I can't simply return after each call to fail(). What I really want is a way to completely bail out of the servlet after forwarding. How do I do that?
[ April 11, 2006: Message edited by: Dan Tenenbaum ]
 
Sheriff
Posts: 67746
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
Throw an exception when you detect the error and configure the web.xml to show the appropriate error page upon detecting that exception. No goo in the servlet necessary.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
..........................
 
reply
    Bookmark Topic Watch Topic
  • New Topic