• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

setting a session attribute from javascript

 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
JavaScript can not do it.

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

Eric
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Great minds think alike...
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic