GeeCON Prague 2014*
The moose likes JSP and the fly likes why javascript is not getting the refreshed session attribute from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "why javascript is not getting the refreshed session attribute from JSP" Watch "why javascript is not getting the refreshed session attribute from JSP" New topic
Author

why javascript is not getting the refreshed session attribute from JSP

Allok Srivastava
Greenhorn

Joined: Mar 30, 2008
Posts: 3
Hi
I have javascript function in A.jsp page, which will be called using setInterval to check for the session attribute which is being set by B.jsp page.
But when i check for the attribute value, it gives null in A.jsp page, bcoz, my java script couldn't able to pick up the refreshed session value.
What am i doing wrong, please help me to resolve this problem
Any help is highly appreciated.

Thanks
Smitha
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

Your session attribute is on the server. JavaScript executes on the client and has no access whatsoever to the session.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61310
    
  66

it gives null in A.jsp page, bcoz,
Please use real words when posting to the forums. Abbreviations such as "bcoz" in place of "because" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please read this for more information.

thanks,
bear
JavaRanch sheriff
Allok Srivastava
Greenhorn

Joined: Mar 30, 2008
Posts: 3
Thanks Bear,
but my javascript is itself in the JSP page.
Sample code as follows:
A.jsp


In A.jsp, my status attribute will allways return null, when i refresh the A.jsp page after executing B.jsp, it gives the proper result.
Please help me to solve this.

Thanks
Smitha
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

The fact that the code is mixed in the same file doesn't change what Bear said.

The best way to get a handle on this is to get in the habit of looking at the HTML source of your pages (using your browser's view page source feature). This is what is created by JSP and passed to your browser.
Your JSP code and your Javascript code are interpreted on two different machines, at different times.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
GeeCON Prague 2014
 
subject: why javascript is not getting the refreshed session attribute from JSP