This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes Session Attribute Values Fom JS Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Reply 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: 1261
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: 56543
    
  14

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 ]

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Steve Dyke
Ranch Hand

Joined: Nov 16, 2004
Posts: 1261
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: 56543
    
  14

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
 
Similar Threads
Shorten conditions
Static Methods in Java
Variable declaration inside loops - what happens?
Inheritance Variable assignment
j2ee install 1.3.1 on dapper