• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaScript: Please Help

 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 70
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its not possible to validate session in javascript as its a client-side technology...

But you can do it using AJAX...
 
Campbell Ritchie
Sheriff
Posts: 48370
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We discuss JavaScript elsewhere. Moving thread.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64613
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaScript has no clue about this unless you set some sort of cookie that informs it of the time.

Eric
 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
 
Kushagra Bindal
Ranch Hand
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 156
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 874
Android Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic