Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Losing my ServletRequest object after throwing an Exception?  RSS feed

 
Jeff Wachhorst
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the travel web application I'm writing, my front controller servlet calls a POJO that throws a custom exception whose class is a class I have written. The servlet has passed the ServletRequest to the POJO when it instantiated it. I throw the exception when a List I'm populating has had nothing added to it because the user's input specified a parameter for which no information can be found.

Here is my throws clause:

In NoFlightsFoundException, I do this:

In my web.xml, I route control back to the input screen where the user entered their departure city and use a <c:if..> tag like so:

The first time I execute the application, entering a city for which no flights will be found, it all works fine; the input screen

comes up with the message. However, when I enter another faulty city name, the screen finds no message to display. What's happening

is that I'm getting a NullPointerException on the request.setAttribute(..) statement in NoFlightsFoundException. However, the

message is being passed successfully to NoFlightsFoundException. It's looking like the NullPointerException is thrown because the

request itself is no longer there. How can this be? It isn't complaining that it can't find the message to set in the setAttribute

(..) because I've verified that the message exists. The first time I enter my info on my input screen (where I specify a departure

city), a System.out.println(request.getScheme()) in NoFlightsFoundException shows "http". The second time (when the message fails

to get set by the request.setAttribute(..), the System.out.println(request.getScheme()) shows null.
Is this making any sense or ringing a bell to anyone? Let me know if I can provide more info and/or clarify further..

Thank you in advance!
 
Jeff Wachhorst
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So sorry, please note this correction:
This:
In my web.xml, I route control back to the input screen where the user entered their departure city and use a <c:if..> tag like so:

should read like this:
In my web.xml, I route control back to the input screen where the user entered their departure city and in that input screen, I use a <c:if..> tag like so:
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!