aspose 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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Servlets
Reply 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: 902


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

Joined: Jan 10, 2002
Posts: 56185
    
  13

Where?


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 902
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: 503

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)


Regards, Prasad
SCJP 5 (93%)
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 902
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: 56185
    
  13

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: 902
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: 56185
    
  13

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: 902
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: 56185
    
  13

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: 902
okay, i got it, it's 30....
Thank you.....
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56185
    
  13

 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Getting NullPointerException while counting number of visitors using session
 
Similar Threads
primitive as attribute
question about session?
getSession(false) at first request
sharing data
Question on HttpSession