• 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
  • Paul Clapham
  • Tim Cooke
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Frank Carver
  • Henry Wong
  • Ron McLeod
Saloon Keepers:
  • Tim Moores
  • Frits Walraven
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Himai Minh

How can I use a javascript var in my jsp?

 
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everybody;
I imported a javascript file in my jsp and I need to use a global var defined in js file.
How can I do that?
Yhank You!
 
Sheriff
Posts: 67671
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From where? Other JavaScript code? Or are you still writing Java code in your JSPs (very old-fashioned!) and want to access it there?

If the former, no problem. The fact that the page is a JSP is moot as far as the JavaScript is concerned.

If the latter, you can't. Java code in a JSP (which you should not be writing) runs on the server long before the page gets sent to the browser where the JavaScript is interpreted. If that's confusing to you, maybe this article will help.
 
Brucaliffo John
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so, if I need to use var in a java code included in my jsp there's no way. <% %>
right?

Thank you
 
Bear Bibeault
Sheriff
Posts: 67671
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you read the article?
 
Brucaliffo John
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.
I'm working on an existing prject.
There's a javascript file that perform open and close menu actions (struts-menu).
I have to change menu tooltip in "CLOSE" if the menu is opened and "OPEN" if the menu is closed.
The code that creates menu and set the tooltips is included in a scriptlet in a jsp page.
How can I retrieve the information on menu status (open or close) and use it to set the tooltip in my java code?

Thank you very much.

p.s.
sorry but english is not my first language
 
Once upon a time there were three bears. And they were visted by a golden haired tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic