• 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
  • Devaka Cooray
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Jeanne Boyarsky
  • Tim Cooke
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Mikalai Zaikin
  • Carey Brown
Bartenders:

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: 4116
72
Mac TypeScript Chrome Java Linux
  • 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: 4116
72
Mac TypeScript Chrome Java Linux
  • 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.
 
No matter how many women are assigned to the project, a pregnancy takes nine months. Much longer than this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic