• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Filter crashes when retrieving daa from session  RSS feed

 
Ranch Hand
Posts: 230
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi i have a filter as such



Now why is it crashing ?? In normal servlets doGet() or doPost() if we did the same it wouldnt crash. If the attribute wasnt there it would just show up as null.
Any suggestions??
 
Author and ninkuma
Marshal
Posts: 66806
168
IntelliJ IDE Java jQuery Mac Mac OS X
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66806
168
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Rajesh Khan wrote:In normal servlets doGet() or doPost() if we did the same it wouldnt crash. If the attribute wasnt there it would just show up as null.


Incorrect. If this were in a servlet and the attribute were null, it would "crash" in the exact same way.
 
Sheriff
Posts: 21460
96
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the attribute weren't there then ((HttpServletRequest)request).getSession().getAttribute("fname") would return null, yes. But you are calling toString() on the result. That's going to result in a NullPointerException if the attribute isn't present. Better is this:
 
Rob Spoor
Sheriff
Posts: 21460
96
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rajesh, please UseOneThreadPerQuestion. You've posted the same question (and gotten an answer) here. In other words, I've wasted my time writing my previous reply.
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!