Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting NullPointerException while counting number of visitors using session

 
Punit Jain
Ranch Hand
Posts: 1015
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


i am getting a NullPointerException in this code??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Where?
 
Punit Jain
Ranch Hand
Posts: 1015
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 671
4
Eclipse IDE Java Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1015
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1015
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you don't set a timeout value it will use the default (whatever your container uses).
 
Punit Jain
Ranch Hand
Posts: 1015
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1015
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay, i got it, it's 30....
Thank you.....
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65227
95
IntelliJ IDE Java jQuery Mac Mac OS X
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic