Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Accessing javascript variable in jsp

 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there any way I can use javascript variable in my jsp.
 
Marshal
Posts: 67496
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.

Please read this article.
 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Depending on the need, I think it will be clever to have some hidden text field then make assign the Javascript variable as the value for your hidden field which could be assessed later by the JSP/Servlets.
 
Bear Bibeault
Marshal
Posts: 67496
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Paul Okeke wrote:Depending on the need, I think it will be clever to have some hidden text field then make assign the Javascript variable as the value for your hidden field which could be assessed later by the JSP/Servlets.


Except that I assume he's talking about accessing the value in the same JSP that generates the page -- which is, of course, impossible.
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is no direct way but using some javascript and ajax trick it is possible. If if you have several use cases like that you can build a jsp which will be called via ajax. In the url pass this javascript variable as parameter. Get this parameter from request in that new JSP and put it in session. But this trick may not be applicable to all use cases. The better way is to redesign the way you are currently building the page. Think different.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic