aspose file tools*
The moose likes Servlets and the fly likes Filter crashes when retrieving daa from session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Filter crashes when retrieving daa from session" Watch "Filter crashes when retrieving daa from session" New topic
Author

Filter crashes when retrieving daa from session

Rajesh Khan
Ranch Hand

Joined: Oct 16, 2011
Posts: 230
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

Joined: Jan 10, 2002
Posts: 61648
    
  67

Crash? (ItDoesntWorkIsUseless)


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

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

Joined: Oct 27, 2005
Posts: 19760
    
  20

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:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19760
    
  20

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.
 
Consider Paul's rocket mass heater.
 
subject: Filter crashes when retrieving daa from session