Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Filter crashes when retrieving daa from session

 
Rajesh Khan
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??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64607
86
IntelliJ IDE Java jQuery Mac Mac OS X
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64607
86
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.
 
Rob Spoor
Sheriff
Pie
Posts: 20492
54
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
Pie
Posts: 20492
54
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