File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes JSP, JavaBean Coding with JavaScript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP, JavaBean Coding with JavaScript" Watch "JSP, JavaBean Coding with JavaScript" New topic

JSP, JavaBean Coding with JavaScript


Joined: Jan 07, 2002
Posts: 4
Is there a way whereby the values of JSP variables be assigned to the JavaScript variables and vice versa?
Mani Balasubramanian

Joined: Jan 03, 2002
Posts: 15
Have you tried this
Jsp variable in javascript:
<script language="javascript">
var javascriptVar = "<%=jspVar%>";
The otherway round is not possibile directly. Either you have to pass the javascript variable as a url to another jsp page or submit the page to another jsp page with javascript variable as a hidden field.

Joined: Jan 07, 2002
Posts: 4
i have tried the example u gave me but it will give me syntax error when i run it.
Angela Poynton
Ranch Hand

Joined: Mar 02, 2000
Posts: 3143
When you tried it did you assign a value to jspVar??

You might want to print out javascriptVar in the Javascript too!!

Pounding at a thick stone wall won't move it, sometimes, you need to step back to see the way around.

Joined: Jan 07, 2002
Posts: 4
i did assign the values to the JSP variable n assign to JavaScript variable but it will give me error - syntax error.
David O'Meara

Joined: Mar 06, 2001
Posts: 13459

The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at .
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please re-register with a new name which meets the requirements.
I agree. Here's the link:
subject: JSP, JavaBean Coding with JavaScript
It's not a secret anymore!