• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Jj Roberts
  • Tim Holloway
  • Piet Souris
Bartenders:
  • Himai Minh
  • Carey Brown
  • salvin francis

lifetime of pageContext?

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Integer count = new Integer("0");
pageContext.setAttribute("COUNT", count, PageContext.SESSION_SCOPE);

this is what i do in a JSP. in other JSPs i get this attribute. everything works fine. but yesterday i left my web application running. in the morning when i came and worked through some pages of the web applications, it gave null pointer exception for the code that gets this "COUNT" object from the pageContext. Why? please help, as i need to let my application run over months together.
 
Marshal
Posts: 67478
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You did not place your variable in page context. You used the page context to place your variable in the session context. The session times out after a period set for it in the server configuration.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
use this
pageContext.setAttribute("count", count, pageContext.APPLICATION_SCOPE)
 
Neeraj Macker
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i fail to understand this SESSION_SCOPE thing. i made a test jsp which had NO HttpSession. i just added a string to a pageContext.SESSION_SCOPE and then read it. i did get back the value. i dont understand from where does the pageContext gets the http session? does the container create a http session implicitly?and where can i set the maxinactiveinterval setting for this jsp session. in the <session-timeout> in web.xml. please explain this session thing.
 
Bear Bibeault
Marshal
Posts: 67478
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

does the container create a http session implicitly?



Yes.
 
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
setMaxinactiveinter..() & session timeout both are for sessions only. But if the former is used in the code and the later in the deplyment descp. To neverr end the session use negative or 0 as the value.
Note: the former taks in secs the later in mins
If this helped ..do reply
 
Neeraj Macker
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks Deepa and Bear. i opened the _jsp.java file in tomcat work directory and found the method used by tomcat servlet container to create a new PageContext. it creates a session for every page context. and hence i now understand. thanks a lot.
 
Neeraj Macker
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
one more question:

i have set the max inactive interval in DD to -1 i.e. infinite. But what i actually want is that the session exists as long as the IE exists and the session invalidates when i close the IE. but this does not happen. what should i do?is there any other option?
 
Neeraj Macker
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
someone please reply.
 
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can write a javascript function and then in an scriplet you can write something like onUnload <% session.invalidate() %>

I am not sure if this is the correct syntax but I think this is one of the solutions. hope this helps
 
Deepa Korecherla
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This mite be the very crude solution...try this
when u close the window (in the window close method) take the time ( in mins...diff. of the initial time & window close time) and put that mins number in the setmaxinactive..(mins). This may not be the sol. I'm sure there is another easier sol.
do reply ..what u've done
 
Deepa Korecherla
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Qureshi is right...my idea of taking time in mins may not work
 
Bear Bibeault
Marshal
Posts: 67478
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I think you can write a javascript function and then in an scriplet you can write something like onUnload <% session.invalidate() %>



This will not work. All Java is executed on the server prior to the page being sent to the browser. Emedding a scriptlet in a Javascript function will not cause that scriptlet to execute when the Javascript function is triggered.
 
Neeraj Macker
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Bear Bibeault:


This will not work. All Java is executed on the server prior to the page being sent to the browser. Emedding a scriptlet in a Javascript function will not cause that scriptlet to execute when the Javascript function is triggered.



please suggest a solution...
 
what if we put solar panels on top of the semi truck trailer? That could power this tiny ad:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic