• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Use a JSP variable in JavaScript? Plz Help

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Firstly I am new to JavaScript.
I have a JSP page.
There is a chunk of JSP code that creates a String variable.
On this page there is also a chunk of code that I was given with encode and decode functions. These functions take a pair of strings and encrypt them. 1 Of the stings that I need to use in this function is created via JSP code.
So I need to get this JSP String variable to work in the encode function.
I know how to display JSP strings in HTML - but I dont know how to use them in JavaScript. Is it possible?
Also with the result of the encode function that is in JavaScript - I need to send the result in a form on that page.
My second question is how do you access JavaScript variables in HTML so that I can send it via a hidden value in a form?
 
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
1.
<%
String s = "Java";
%>
<script>
...
document.[formName].[fieldName].value="<%= s %>";
...
</script>
2.
<%
String x1 = null;
%>
<script>
...
var s1 = "JAVA";
if(s1 != "")
{
<%
x1="Any Computed Value or JAVA";
%>
}
...
</script>
<INPUT TYPE=HIDDEN NAME="Counter" VALUE="<%=x1%>">
Hope this helps.
Suresh Selvaraj
Sun Certified Java Programmer
 
Daniel Iszatt
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thankyou for that. It looks good.
I'll try it out next time I'm at work.
 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,
The method of embedding the scriplet in the script is fine but when a user views the code it is clearly visible. in case the javascript is in a file how do we access a bean ?
 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no way of accessing a java bean from javascript as the bean is a sever side entity, whereas the javascript runs on the browser once the server request has been completed.
The only way of including jsp values in an included file is either to make the.js file a .jsp and then including it exactly as if it were a normal javascript file, or by declaring and defining variables within script tags in your main JSP, and referencing them in the included javascript file.
 
jini jane
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Pete.
 
BWA HA HA HA HA HA HA! Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic