spiderman19
asked on
HttpSession related
hi all,
i have this in my jsp page and within my servlet.
userObject userSession = (userObject)session.getAtt ribute("us erSession" );
in my tomcat, i have set in web.xml to this
<session-config>
<session-timeout>50</sessi on-timeout >
</session-config>
Now i wish to display some sort like indicator to the user when the session is ABOUT to end and the system will redirect to logut.jsp screen.
Any ideas how to perform this?
I have read the docs, i can only see this is useful, yet it's bring no meaning to me if i do this
<%= session.getMaxInactiveInte rval() %>
i have this in my jsp page and within my servlet.
userObject userSession = (userObject)session.getAtt
in my tomcat, i have set in web.xml to this
<session-config>
<session-timeout>50</sessi
</session-config>
Now i wish to display some sort like indicator to the user when the session is ABOUT to end and the system will redirect to logut.jsp screen.
Any ideas how to perform this?
I have read the docs, i can only see this is useful, yet it's bring no meaning to me if i do this
<%= session.getMaxInactiveInte
ASKER
Boon Leng, thanks for the comments. Wondering how can i call this setTimeoout? if put within the <body> tag or with onClick version?
But to make it sound more sense, i think should keep it display somewhere in the page.. to constantly showing the user, how many times left if he didnt give a respond back.
But what do you think?
But to make it sound more sense, i think should keep it display somewhere in the page.. to constantly showing the user, how many times left if he didnt give a respond back.
But what do you think?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
sorry the function calculateTime should look like
function calculateTime()
{
if (remainingTime > 0)
{
window.setTimeout("calcula teTime", 1000);
displayTime();
remainingTime = remainingTime - 1;
}
}
arunrs
function calculateTime()
{
if (remainingTime > 0)
{
window.setTimeout("calcula
displayTime();
remainingTime = remainingTime - 1;
}
}
arunrs
I still beat you to it ;)
Small typo error. It should be
window.setTimeout("calcula teTime()", 1000);
instead of
window.setTimeout("calcula teTime", 1000);
arunrs
window.setTimeout("calcula
instead of
window.setTimeout("calcula
arunrs
You sure did Michel.:)
Also it is sensible to display the remaining time in window rather than in status bar. :)
Also it is sensible to display the remaining time in window rather than in status bar. :)
ASKER
ok guys..
let me try each of your ideas and got any problems will come to you again
let me try each of your ideas and got any problems will come to you again
ASKER
hi, this is the code i have in my page:
<script type="text/javascript">
timeToLeave = <%= (session.getMaxInactiveInt erval() * 1000) - 170000 %>;
secs = parseInt(timeToLeave/1000) ;
function showTimer() {
var show=document.getElementBy Id('show') ;
secs--
var plur=(secs==1)?'':'s';
if (timeToLeave<0) secs*=-1;
if (show) show.innerHTML='Your session '+(timeToLeave >0)+'will timeout in '+secs+' second'+plur+'timedout '+secs+' second'+plur+' ago';
}
setInterval('showTimer()', 1000);
</script>
with some amendment that i have add in to sovle some typo errors.
But i wish to change to this, * to redirect the entire page to "login.jsp". Is that suppose to code like that? bt it's not working.
if (show && timeToLeave>0 ) {
show.innerHTML='Your session '+(timeToLeave >0)+'will timeout in '+secs+' second'+plur+'timedout '+secs+' second'+plur+' ago';
if (timeToLeave=0) {
window.location="/login.js p";
}
}
but it's not working on the second part...
<script type="text/javascript">
timeToLeave = <%= (session.getMaxInactiveInt
secs = parseInt(timeToLeave/1000)
function showTimer() {
var show=document.getElementBy
secs--
var plur=(secs==1)?'':'s';
if (timeToLeave<0) secs*=-1;
if (show) show.innerHTML='Your session '+(timeToLeave >0)+'will timeout in '+secs+' second'+plur+'timedout '+secs+' second'+plur+' ago';
}
setInterval('showTimer()',
</script>
with some amendment that i have add in to sovle some typo errors.
But i wish to change to this, * to redirect the entire page to "login.jsp". Is that suppose to code like that? bt it's not working.
if (show && timeToLeave>0 ) {
show.innerHTML='Your session '+(timeToLeave >0)+'will timeout in '+secs+' second'+plur+'timedout '+secs+' second'+plur+' ago';
if (timeToLeave=0) {
window.location="/login.js
}
}
but it's not working on the second part...
ASKER
i means the window redirecting doesnt work
Anyway I meant
if (show) show.innerHTML='Your session '+(timeToLeave >0)?'will timeout in '+secs+' second'+plur:'timedout '+secs+' second'+plur+' ago';
sorry.
So the script is
<script type="text/javascript">
timeToLeave = <%= (session.getMaxInactiveInt erval() * 1000) - 170000 %>;
secs = parseInt(timeToLeave/1000) ;
tId="";
function showTimer() {
if (timeToLeave==0) {
clearInterval(tId);
window.location.replace("/ login.jsp" );
}
var show=document.getElementBy Id('show') ;
secs--
var plur=(secs==1)?'':'s';
if (show) show.innerHTML='Your session will timeout in '+secs+' second'+plur
}
tId= setInterval('showTimer()', 1000);
</script>
if (show) show.innerHTML='Your session '+(timeToLeave >0)?'will timeout in '+secs+' second'+plur:'timedout '+secs+' second'+plur+' ago';
sorry.
So the script is
<script type="text/javascript">
timeToLeave = <%= (session.getMaxInactiveInt
secs = parseInt(timeToLeave/1000)
tId="";
function showTimer() {
if (timeToLeave==0) {
clearInterval(tId);
window.location.replace("/
}
var show=document.getElementBy
secs--
var plur=(secs==1)?'':'s';
if (show) show.innerHTML='Your session will timeout in '+secs+' second'+plur
}
tId= setInterval('showTimer()',
</script>
ASKER
mplugin, this is my final code: Everything work fine excecpt the redirecting part..
<script type="text/javascript">
alert( <%= (session.getMaxInactiveInt erval() * 1000) - 115000 %> );
timeToLeave = <%= (session.getMaxInactiveInt erval() * 1000) - 115000 %>;
secs = parseInt(timeToLeave/1000) ;
tId="";
function showTimer() {
if (timeToLeave=0) {
clearInterval(tId);
window.location.replace("/ login.jsp" );
}
var show=document.getElementBy Id('show') ;
secs--;
var plur=(secs==1)?'':'s';
if (show) show.innerHTML='Your session will timeout in '+secs+' second'+plur;
}
tId= setInterval('showTimer()', 1000);
</script>
i have try to change couple of things.. but then still not able to see the page (login.jsp) come out. nothing at all.
<script type="text/javascript">
alert( <%= (session.getMaxInactiveInt
timeToLeave = <%= (session.getMaxInactiveInt
secs = parseInt(timeToLeave/1000)
tId="";
function showTimer() {
if (timeToLeave=0) {
clearInterval(tId);
window.location.replace("/
}
var show=document.getElementBy
secs--;
var plur=(secs==1)?'':'s';
if (show) show.innerHTML='Your session will timeout in '+secs+' second'+plur;
}
tId= setInterval('showTimer()',
</script>
i have try to change couple of things.. but then still not able to see the page (login.jsp) come out. nothing at all.
TWO equal signs - why do you insist on removing one of them?
if (timeToLeave==0) {
a=0; // setting a to 0
if (a==0) // asking if a is equal to 0
Michel
if (timeToLeave==0) {
a=0; // setting a to 0
if (a==0) // asking if a is equal to 0
Michel
ASKER
ok.. my mistake.
but then even i add in back the "==" sign, its still didnt redirect to the login.jsp
but then even i add in back the "==" sign, its still didnt redirect to the login.jsp
Hi,
I have a doubt...
Is it
if (timeToLeave==0) or is it
if (secs==0) ??
arunrs
I have a doubt...
Is it
if (timeToLeave==0) or is it
if (secs==0) ??
arunrs
And I am sorry I did not pay attention:
if (secs<=0) {
not
if (timeToLeave==0) {
if (secs<=0) {
not
if (timeToLeave==0) {
Better:
if (secs<=0) {
clearInterval(tId);
window.location.replace("http://www.google.com" );
return;
}
if (secs<=0) {
clearInterval(tId);
window.location.replace("http://www.google.com"
return;
}
ASKER
BINGOOOOOOOOOOOO
but guys...
my page is having frame....
means, it's something like this...
-------------------------- ---------- -----
top.jsp
-------------------------- ---------- ----
|
|
left.jsp | main.jsp
|
|
|
the www.google.com only affect the main.jsp as my main.jsp is there..... how to reflect the entire page when secs ==0?
but guys...
my page is having frame....
means, it's something like this...
--------------------------
top.jsp
--------------------------
|
|
left.jsp | main.jsp
|
|
|
the www.google.com only affect the main.jsp as my main.jsp is there..... how to reflect the entire page when secs ==0?
that would be
top.location.replace("http://www.google.com")
unless you only have one level of frames.
But what do you mean by
the www.google.com only affect ....
top.location.replace("http://www.google.com")
unless you only have one level of frames.
But what do you mean by
the www.google.com only affect ....
ASKER
this is my final code. Both. parent.location or top.location is work either way.
<script type="text/javascript">
alert( <%= (session.getMaxInactiveInt erval() * 1000) - 1195000 %> );
timeToLeave = <%= (session.getMaxInactiveInt erval() * 1000) - 1195000 %>;
secs = parseInt(timeToLeave/1000) ;
tId="";
function showTimer() {
if (secs==0) {
clearInterval(tId);
top.location.replace("logi n.jsp");
return;
}
var show=document.getElementBy Id('show') ;
secs--;
var plur=(secs==1)?'':'s';
if (show) show.innerHTML='Your session will timeout in '+secs+' second'+plur;
}
tId= setInterval('showTimer()', 1000);
</script>
Anyway, thanks for your both help.
<script type="text/javascript">
alert( <%= (session.getMaxInactiveInt
timeToLeave = <%= (session.getMaxInactiveInt
secs = parseInt(timeToLeave/1000)
tId="";
function showTimer() {
if (secs==0) {
clearInterval(tId);
top.location.replace("logi
return;
}
var show=document.getElementBy
secs--;
var plur=(secs==1)?'':'s';
if (show) show.innerHTML='Your session will timeout in '+secs+' second'+plur;
}
tId= setInterval('showTimer()',
</script>
Anyway, thanks for your both help.
Hi,
I have one more doubt...
It is mentioned that "<%= (session.getMaxInactiveInt erval() %>" gives values in seconds.
Then why should we use
timeToLeave = <%= (session.getMaxInactiveInt erval() * 1000) - 1195000 %>;
secs = parseInt(timeToLeave/1000) ;
to get the value in seconds...
Sorry, if this seems absurd but I don't know anything about the
<%= (session.getMaxInactiveInt erval() %>
arunrs
I have one more doubt...
It is mentioned that "<%= (session.getMaxInactiveInt
Then why should we use
timeToLeave = <%= (session.getMaxInactiveInt
secs = parseInt(timeToLeave/1000)
to get the value in seconds...
Sorry, if this seems absurd but I don't know anything about the
<%= (session.getMaxInactiveInt
arunrs
We SHOULD not.
timeToLeave = <%= (session.getMaxInactiveInt erval() * 1000) - 1195000 %>;
secs = parseInt(timeToLeave/1000) ;
can be written
secs= <%= session.getMaxInactiveInte rval() - 1195 %>;
if you do not need a date object
Michel
timeToLeave = <%= (session.getMaxInactiveInt
secs = parseInt(timeToLeave/1000)
can be written
secs= <%= session.getMaxInactiveInte
if you do not need a date object
Michel
So if you want to provide some alert to the user when session is about to timeout, you would need to do this using javascript setTimeout().
Example:
<script type="text/javascript">
setTimeout("alert('Session
</script>
session.getMaxInactiveInte
then minus the time (e.g 10000 miliseconds) before session timeout for the alert to be prompted.
Hope this can help.
Regards,
Boon Leng