aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Session Attribute Values Fom JS 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 "Session Attribute Values Fom JS" Watch "Session Attribute Values Fom JS" New topic
Author

Session Attribute Values Fom JS

Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1490
    
    1
Have I been dreaming, totally crazy, or what?

I was under the impression that if I

had code in servlet like session.setAttribute("myVar");

Then in JS I could get that value with

var v1 = "${myVar}"

Am I wrong?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

You're not crazy, just a tad confused.

That's not JavaScript, that's JSP.

By the time the page gets to the browser, what it sees is:The substitution occurs on the server long before the HTML gets sent to the browser.

P.S. Don't forget your semi-colons!
[ December 19, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1490
    
    1
So if from my page I call a jQuery.getJSON("/myServlet") Then in that servlet do a session.setAttribute("myVar","1234"). Then back on the calling page call a function var v1 = "${myVar}" will fail.

What I want to do is from my navigation page(based on a users log on) set a global value for that session.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

You didn't mention Ajax.

Yeah, an Ajax call to another resource will have no effect on the page currently loaded.

If you want the value of a session scoped variable, you'll need to pass it back as part of the JSON data.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session Attribute Values Fom JS