Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing javascript variable in jsp

 
p hasini
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.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No.

Please read this article.
 
Paul Okeke
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
Author and ninkuma
Marshal
Pie
Posts: 65115
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • 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.
 
Vikas Aggarwal
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic