File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes Getting NullPointerException while counting number of visitors using session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Getting NullPointerException while counting number of visitors using session" Watch "Getting NullPointerException while counting number of visitors using session" New topic
Author

Getting NullPointerException while counting number of visitors using session

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2


i am getting a NullPointerException in this code??
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Where?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
At line 16..

here is the exception



HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

java.lang.NullPointerException
VisitorsUsingSession.doGet(VisitorsUsingSession.java:16)
javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)


note The full stack trace of the root cause is available in the Apache Tomcat/6.0.14 logs.

Prasad Krishnegowda
Ranch Hand

Joined: Apr 25, 2010
Posts: 587
    
    3

Punit Jain wrote:

It obviously throws NullPointerException, because you check if session is null, if its null, then you call session.setAttribute, perhaps you forgot to assign session in above line, i.e request.getSession(true), it should have been session = request.getSession(true)
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
okay, working now....thanks...
one more thing i want to know, when my session gets expired...
what i was expecting is, when i close my browser my session gets expired, apart from browser even when i m stopping my server my session is not expiring...

please let me know where i m going wrong??
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

The server has no idea that you have closed the browser. How can it expire the session when that happens? The session will eventually time-out.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
Bear Bibeault wrote:The server has no idea that you have closed the browser. How can it expire the session when that happens? The session will eventually time-out.


okay so either it will eventually time out, otherwise i have to set session Timeout..?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

If you don't set a timeout value it will use the default (whatever your container uses).
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
Bear Bibeault wrote:If you don't set a timeout value it will use the default (whatever your container uses).


okay, can i see what my container/tomcat, default timeout value??
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Well, Tomcat uses the conf/web.xml config file as the default for all web apps. Maybe you should look in there.
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 1001
    
    2
okay, i got it, it's 30....
Thank you.....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting NullPointerException while counting number of visitors using session