wood burning stoves 2.0*
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


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
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: 60794
    
  65

Crash? (ItDoesntWorkIsUseless)


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

Joined: Jan 10, 2002
Posts: 60794
    
  65

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: 19655
    
  18

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: 19655
    
  18

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Filter crashes when retrieving daa from session
 
Similar Threads
How to make Filter getting called only once for every User
filter, chain.doFilter(request, response);
struts 2 validation and prevent double submit
Filter
servlet filter sendRedirect