Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

forwarding not quite working  RSS feed

 
Dan Tenenbaum
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66204
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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.
 
lei zhang
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
..........................
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!