Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Servlets
Search Coderanch
Advance search
Google search
Register / Login
Win a copy of
OCP Oracle Certified Professional Java SE 21 Developer Study Guide: Exam 1Z0-830
this week in the
Programmer Certification
forum!
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
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
Liutauras Vilda
Jeanne Boyarsky
paul wheaton
Sheriffs:
Ron McLeod
Devaka Cooray
Henry Wong
Saloon Keepers:
Tim Holloway
Stephan van Hulst
Carey Brown
Tim Moores
Mikalai Zaikin
Bartenders:
Frits Walraven
Forum:
Servlets
Notify Users before session expires
Meet Gaurav
Ranch Hand
Posts: 492
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Hi,
I saw in few sites, the users were getting a alert before the session expires. How to achieve that..
is their any way we can invoke the Javascript window.open from
JSP
before the session time.. Please assist me
Paul Sturrock
Bartender
Posts: 10336
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
It's usually something like a JavaScript timer plus an AJAX request to stop the session expiring (assuming the user responds) or remove the popup if they don't
JavaRanch FAQ
HowToAskQuestionsOnJavaRanch
Meet Gaurav
Ranch Hand
Posts: 492
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Thanks Paul..
I googled and I got the below code.
var secondsBeforeExpire = <c:out value="${pageContext.session.maxInactiveInterval}"/>; alert(secondsBeforeExpire); var timeToDecide = 15; // Give client 15 seconds to choose. setTimeout(function() { alert('Your session is about to timeout in ' + timeToDecide + ' seconds!') }, (secondsBeforeExpire - timeToDecide) * 1000);
I guess I need to submit 1 ajax request to server saving client is alive.. Am I rite.
Thanks
Paul Sturrock
Bartender
Posts: 10336
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Yeah.
JavaRanch FAQ
HowToAskQuestionsOnJavaRanch
Meet Gaurav
Ranch Hand
Posts: 492
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Paul I got struck in AJAX call.. Please help
Call is not going to my handler..
function submitExtend() { alert("AJAX CALL"); var params= 'userName=xxxxx' + '&password=aaaaa'; var urlpost= 'MainHandler.do' ; makeGetRequest( urlpost, params ); } function createRequestObject() { var tmpXmlHttpObject; if(window.XMLHttpRequest) { tmpXmlHttpObject = new XMLHttpRequest(); } else if (window.ActivexObject) { tmpXmlHttpObject = new ActiveXobject("Microsoft.XMLHTTP"); } return tmpXmlHttpObject; } var http; function makeGetRequest(url, params) { alert(params); alert(url); http = createRequestObject(); http.open('POST', url, true); http.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); http.setRequestHeader("Content-length", params.length); http.onreadystatechange = processResponse; http.send(params); } function processResponse() { if(http.readyState == 4) { document.getElementById('header').innerHTML = "You have not typed Anything"; } }
Bear Bibeault
Sheriff
Posts: 67752
173
I like...
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Ajax is much much easier if you use one of the popular JavaScript libraries such as jQuery or Dojo.
[
Asking smart questions
] [
About Bear
] [
Books by Bear
]
Meet Gaurav
Ranch Hand
Posts: 492
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Finally This code works fine...... Ajax call is going to server now..
<script type="text/javascript"> function getXMLObject() //XML OBJECT { var xmlHttp = false; try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP") // For Old Microsoft Browsers } catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP") // For Microsoft IE 6.0+ } catch (e2) { xmlHttp = false // No Browser accepts the XMLHTTP Object then false } } if (!xmlHttp && typeof XMLHttpRequest != 'undefined') { xmlHttp = new XMLHttpRequest(); //For Mozilla, Opera Browsers } return xmlHttp; // Mandatory Statement returning the ajax object created } var xmlhttp = new getXMLObject(); //xmlhttp holds the ajax object function ajaxFunction() { var getdate = new Date(); //Used to prevent caching during ajax call if(xmlhttp) { xmlhttp.open("GET","MainHandler.do",true); //gettime will be the servlet name xmlhttp.onreadystatechange = handleServerResponse; xmlhttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xmlhttp.send(null); alert("Sent........."); } } function handleServerResponse() { if (xmlhttp.readyState == 4) { if(xmlhttp.status == 200) { document.myForm.time.value=xmlhttp.responseText; //Update the HTML Form element } else { alert("Error during AJAX call. Please try again"); } } } </script>
Sometimes am getting below alert
alert("Error during AJAX call. Please try again");
But still the call is going to Action handler(
servlet
).. Someone please assist me why am getting this error.
He got surgery to replace his foot with a pig. He said it was because of this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Getting access to HttpServletResponse with in sessionDestroyed Method of HttpSessionListener
how to use Session in Struts
Servlet without timeout
Session Time out in JSP
valueUnbound() not getting called
More...