aspose file tools*
The moose likes JSP and the fly likes Accessing javascript variable in jsp Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Accessing javascript variable in jsp" Watch "Accessing javascript variable in jsp" New topic
Author

Accessing javascript variable in jsp

p hasini
Ranch Hand

Joined: Oct 24, 2009
Posts: 92
Is there any way I can use javascript variable in my jsp.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

No.

Please read this article.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Okeke
Ranch Hand

Joined: May 16, 2009
Posts: 58
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.


OCJP 1.6
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61764
    
  67

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

Joined: Jun 22, 2001
Posts: 140
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.


Vikas Aggarwal

Founder @
Leads and Deals Limited

www.LeadsAndDeals.com
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Accessing javascript variable in jsp