File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Attribute Values Fom JS

 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64175
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Steve Dyke
Ranch Hand
Posts: 1602
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64175
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic