• 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
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Setting a session attribute through JS

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I have a requirement that on click of a hyperlink from a jsp, i want to set a session attribute in the javascript.
On click of the hyperlink there will be 2 parameters passed to the JS function and in that JS function i want to set the 2 variables in session.
Can i achieve this through javascript by using something like session.setAttrbute("key","value");

Thanks
Gurvinder
 
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. JavaScript works at the client side (i.e: browser) but the "session" object exists in the server.
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can set those attributes through server side. Once you submit the page to the server you may get the required values through request.getParameter() and then set it to the session.
 
Gurvinder Singh
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Actually my requirement is to do that in the JS without submitting a form.
Is there any other way i can do it or any work around for it?

Any suggestions welcome....

-Gurvinder
 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Gurvinder Singh wrote:Hi

I have a requirement that on click of a hyperlink from a jsp, i want to set a session attribute in the javascript.
On click of the hyperlink there will be 2 parameters passed to the JS function and in that JS function i want to set the 2 variables in session.
Can i achieve this through javascript by using something like session.setAttrbute("key","value");

Thanks
Gurvinder



It may be possible if you submit the two parameters as form fields to the servlet where you read these and set them in the session.

But if you don't want to submit the form, you may pass the parameters through using Ajax call also. Please lemme know if you want to know how to do the same.
 
Gurvinder Singh
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeah sure Samrat

i would like to know that. Probably if you can provide me some detailed steps of doing it, it will be great.
But yea just for your info, i want to set the attributes on click of a href in the JS function.

Thanks
Gurvinder
 
Gurvinder Singh
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey

Can anybody help me in this regard of how to set any session attribute through ajax calls.
Please go through the following message chain and suggest me how should i proceed.


Thanks
Gurvinder
 
Vijitha Kumara
Bartender
Posts: 4109
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think a tutorial like this will help you get started with AJAX. Once you are able to send the data to the server it's just normal servlet programming stuff.
 
I've read about this kind of thing at the checkout counter. That's where I met this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic