| Author |
JavaScript varible into Jsp
|
krish
Greenhorn
Joined: Nov 05, 2002
Posts: 5
|
|
HI, I need to put a javascript varible(which is dynamic) into jsp session. Can any one help.... -Thanks Krish
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56162
|
|
Welcome to the Ranch krish! You'll find this forum a great place to seek help on JSP pages, and there aren't many rules you'll have to worry about, but one is that proper names are required. Please take a look at the JavaRanch Naming Policy and change your display name to match it. In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious. Thanks! bear JSP Forum Bartender
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56162
|
|
Now as to your question: Since Javascript executes on the client, it has no access to the session. What you will need to do is to submit a request to the server (either to a JSP or a servlet, preferably the latter) with the value you want to store as a request parameter. The easiest way to do this is probably to submit a form with a hidden input that you've set to the value of the JS variable. bear [ December 31, 2003: Message edited by: Bear Bibeault ]
|
 |
Pat Flickner
Ranch Hand
Joined: Nov 17, 2003
Posts: 173
|
|
Oh, good heavens. I'm very surprised at the responses since we do this all the time: Between the <% and %>: out.println("var variableName = " + jspVarName + ";"); Works like a charm. Pat
|
 |
Pat Flickner
Ranch Hand
Joined: Nov 17, 2003
Posts: 173
|
|
Quick update, in case I assumed too much: <SCRIPT language="JavaScript"> <% out.println("var jsVarName = '" + jspVarName + "';");%> </SCRIPT> Pat
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56162
|
|
Pat, your solution assumes that the question regards getting server-side data into a Javascript variable. The question, rather, was how to get client-side Javascript data into a server-side session. bear
|
 |
Pat Flickner
Ranch Hand
Joined: Nov 17, 2003
Posts: 173
|
|
Arghhh! You're absolutely correct. I read his message three times and still misread it. And you are correct that you would have to pass the variable into a jsp then after the ?. Pat
|
 |
 |
|
|
subject: JavaScript varible into Jsp
|
|
|