Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

setting a session attribute from javascript

 
Ayan Dutta
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi , I need to write a javascript method that sets a session attribute .
This can be done quite easily using scriplet .
But there is a problem .
Say the method is like ...

funtion xyz()
{
if(condition1)
...scriplet code for setting the session attribute
else
...do something else
}

Now when the page containing the method xyz() is loaded ,as the scriplet executes before the javascript ,even if the method xyz() is not invoked ,
the scriplet will get executed.which is not desired.
I know it is not a very good practise to use scriplet from javascript,but the situation is like that.Any work around to prevent this scriplet execution ,when the method is not invoked ?
Regards,
Ayan
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaScript can not do it.

Please read this: http://www.javaranch.com/journal/200510/Journal200510.jsp#a1

Eric
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64983
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ayan Dutta:

I know it is not a very good practise to use scriplet from javascript...


It's not a bad practice, it's impossible. Please read this article to find out why.

You'll have to submit a form or make an Ajax request to have a server-side effect as a result of a client-side event.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64983
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great minds think alike...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic