File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes JS ---> JSP variables Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JS ---> JSP variables" Watch "JS ---> JSP variables" New topic

JS ---> JSP variables

Roberto Diaz
Ranch Hand

Joined: Mar 08, 2002
Posts: 40
How do I assign a Java Script variable to a JSP variable.
Both the variables are of string type.
TIA for all responses.
arul murug

Joined: Aug 08, 2002
Posts: 24
I don't think there is direct way to assign the variable as java script executes at client side and jsp code(as a servlet) at server side.
However u can assign the java script variable to a hidden form field and pass to server where the jsp can get it using request.getParameter().

SCJP2<br />SCWCD<br />UML & OOAD - IBM 486
avina metha

Joined: May 10, 2003
Posts: 3
try this way
<% String string1=request.getParameter("Name");
simillar for others..
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63873

I'm not sure what avina is getting at, but getParameter() will not allow you to access JavaScript variables.
arul on the other hand is quite correct. Think about it for a moment.
The JSP executes on the server in order to format the HTML page which is then sent to the browser wherre it (along with any JavaScript contained within) is interpreted by the browser.
They live in completely separate worlds.
Now, as arul pointed out, the value of the JS variable can be made available to the next JSP page by submitting it as a request parameter.

[Asking smart questions] [About Bear] [Books by Bear]
I agree. Here's the link:
subject: JS ---> JSP variables
It's not a secret anymore!