• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

issues between JSP and javascript

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello everyone!
i just have registered as of now... and i hope you could really help me in this one... i know you can!!
well, my problem is this:
i have made a JSP page with a javascript in it. i would like to ask if it is possible to put a
<% %> tag inside a <script></script> tag?
actually, i have already done this one before, i put a JSP variable with a value in it lets say
<% int JSPInteger = 10; %> inside a javascript tag to transfer that value into a javascript variable.
did you get what i said ? to put into computer terms it will look like this...

<% int JSPInteger = 10; %>
<script>
var JavascriptInteger;
JavascriptInteger = <% JSPInterger %>;
</script>
my question is can JavascriptInteger get the value of JSPInteger?
when i did this, an error occured saying JavascriptInteger was null or not a object..
is there any way to transfer the values of the variables from jsp to javascript and vice versa?
please help... no one can help me in this problem... btw, i also sori for my english grammars, im not really good in my english
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There can be no real collaboration between JSP and JavaScript - the JSP code only generates HTML containing JavaScript. So, this is not in fact a JSP question but a JavaScript question. You need to stare at the resulting HTML+JavaScript and figure out what's wrong from there (I'd suggest using your browser's JavaScript console or similar).
 
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello nene batungbakal,
Please look at the below code....
<% int JSPInteger = 10; %>
<script>
var JavascriptInteger;
JavascriptInteger = "<% JSPInterger %>";
</script>
I had put the jsp scriptlet in quotes while assigning to javascript variable..try this....i wish it will work...
Ravi
 
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ravi's code will work perfectly. Whenever u want to access a JSP variable within javascript u access it as "<%=jspVariableName%>".
 
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
dont you miss the equals sign ?
<%= blabla %> instead of <% blabla %> should work.


k
 
karl koch
Ranch Hand
Posts: 388
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and:
if the server did not complain while compiling your JSP page to a servlet, then the JSP syntax was correct. this does not mean that the javascript you create through the JSP page is correct. if the javascript is faulty, then either it just doesn't work or the browser shows an error message (Javascript-Console in netscape/mozilla, error sign on bottom left in MSIE). As lasse mentioned: check out the resulting HTML code.
k
 
nene batungbakal
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey! thanks a lot guys, the "<%= jspVariableName%>" really works, "" and = quotes really made a lot of difference... silly me...
btw, i checked out the html side of the jsp, and kaboom! it produced the value of the jspVariable... thanks.. hope you can still help me in my future problem..
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic