File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes JavaScript: Please Help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "JavaScript: Please Help" Watch "JavaScript: Please Help" New topic
Author

JavaScript: Please Help

Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi All,
I want to check the session is valid of an application from the javascript. Is it possible o do the same.

If yes then please help me to solve the problem.

Thanks
Kushagra Bindal
Anoop Nair
Ranch Hand

Joined: Oct 29, 2008
Posts: 70
Its not possible to validate session in javascript as its a client-side technology...

But you can do it using AJAX...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38859
    
  23
We discuss JavaScript elsewhere. Moving thread.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61220
    
  66

Please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

A title such as "JavaScript Please Help" is not helpful. What would happen if all posts had such a title?

Please go back and change your post to add a more meaningful subject by clicking the button on your post.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Okie that is my fault. Actually intention was clear to take some help.

Is there no way so that we can determine that wqhen were the last HTTP request were send to server by the browser.

Please help me in that.

Thanks
Kushagra Bindal
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
JavaScript has no clue about this unless you set some sort of cookie that informs it of the time.

Eric
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi Eric,

Thanks for prompt reply. By the way, do you think this is a good way. As on many system cookies are disable.

Is there any other further way.

Thanks
Kushagra Bindal
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6


Ajax update user's Session timeout

Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi Eric,

Thanks for reply. But my task is to redirect to a custom page after the session time out and not refreshing the page. Also I am using JSF. Please suggest if anything is possible according to my need.

Thanks
Kushagra
Austin Tashis
Greenhorn

Joined: May 23, 2003
Posts: 19
If you put an iframe in a hidden element, you should be able to load a document into it with window.open() or by setting its src attribute, and that document can use parent.location=[redirect url] to open your new URL. Since you should know how long a session lasts, you can use setTimeout() to delay checking until the session has expired. Otherwise, loading the hidden page will extend the sesion.
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Thanks for your reply.

But actually our application time out is little bit different type. It is depend on the last hit to the server and on the basis of that hit time out happen. And also out applicaion is divided in various sub template and might be that suggestion won't implement on the same.

Please suggest if any thing is possible in this case.

Thanks
Kushagra Bindal
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


But actually our application time out is little bit different type


why not a simple javascript setTimeout() works in your case. You can set the timeout as same or less than the Server session timeout in body onLoad . when the page timeouts it can redirect ( i mean call ) a URL that maps to your custom page.
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi Balu,

I am using JSF. And in that it will be difficult to maintain the onload function. If it is possible in this case then please suggest me in which way to proceed.

Thanks
Kushagra Bindal
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You do not want to use an onload function with the timer, that would be off. You want to start the timer when the page starts to render.

Eric
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874


Kushagra,
I dont know , how it is different in JSF. if onload isnt the way, try with setTimeout() inside the <script> tag.

setTimeout("document.location.href='/Timeout'",10000);
Kushagra Bindal
Ranch Hand

Joined: Oct 15, 2008
Posts: 156
Hi Balu,

We are making our entry in web.xml for the session time like as



So, can we do this by using javascript, I don't understand that how we can change the set time on click as we are using different js for different layer as might be you already worked on struts or some other framework and better know then me that we are having several layer like tiles in struts and we are currently using different layer and might be for different layer it will be seriously a big mess.

Please correct me if I am wrong.

Thanks
Kushagra Bindal
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You are making this more complicated than it actually is.

You create one external JavaScript file that contains the code for the timeout. The timeout should be the length of your session. You make sure that this file is included on every page. You can also use a meta redirect/refresh tag instead.

Eric
Balu Sadhasivam
Ranch Hand

Joined: Jan 01, 2009
Posts: 874



Kushagara,


So, can we do this by using javascript, I don't understand that how we can change the set time on click as we are using different js for different layer as might be you already worked on struts or some other framework and better know then me that we are having several layer like tiles in struts and we are currently using different layer and might be for different layer it will be seriously a big mess.


If you need the session time out for every page, you got to include it in every page. Like Eric pointed this is simple thing that you are complicating it. define separate js for session time out functionality. I guess with use of tiles (Struts framework) , your job has become more easier . you can simply include the js in any one of the jsp file and thats it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaScript: Please Help